Whitepaper - Ethereum Classic With Cover
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
<strong>Ethereum</strong> <strong>Classic</strong> Documentation, Release 0.1<br />
}<br />
transactionHash: "0x759cf065cbc22e9d779748dc53763854e5376eea07409e590c990eafc0869d74",<br />
transactionIndex: 0<br />
}],<br />
transactionHash: "0x759cf065cbc22e9d779748dc53763854e5376eea07409e590c990eafc0869d74",<br />
transactionIndex: 0<br />
The receipt contains a log. This log was generated by the EVM on transaction execution and included in the<br />
receipt. If we look at the multipy function we can see that the Print event was raised with the input times 7. Since<br />
the argument for the Print event was a uint256 we can decode it according to the ABI rules which will leave us<br />
with the expected decimal 42. Apart from the data it is worth noting that topics can be used to determine which<br />
event created the log:<br />
> web3.sha3("Print(uint256)")<br />
"24abdb5865df5079dcc5ac590ff6f01d5c16edbc5fab4e195d9febd1114503da"<br />
You can read more about events, topics and indexing in the Solidity tutorial.<br />
This was just a brief introduction into some of the most common tasks. See for a full list of available RPC methods<br />
the RPC wiki page.<br />
Web3.js<br />
As we have seen in the previous example using the JSON-RPC interface can be quite tedious and error-prone,<br />
especially when we have to deal with the ABI. Web3.js is a javascript library that works on top of the <strong>Ethereum</strong><br />
RPC interface. Its goal is to provide a more user friendly interface and reducing the chance for errors.<br />
Deploying the Multiply7 contract using web3 would look like:<br />
var source = 'contract Multiply7 { event Print(uint); function multiply(uint input) returns (uint)<br />
var compiled = web3.eth.compile.solidity(source);<br />
var code = compiled.Multiply7.code;<br />
var abi = compiled.Multiply7.info.abiDefinition;<br />
web3.eth.contract(abi).new({from: "0xeb85a5557e5bdc18ee1934a89d8bb402398ee26a", data: code}, funct<br />
if (!err && contract.address)<br />
console.log("deployed on:", contract.address);<br />
}<br />
);<br />
deployed on: 0x0ab60714033847ad7f0677cc7514db48313976e2<br />
Load a deployed contract and send a transaction:<br />
var source = 'contract Multiply7 { event Print(uint); function multiply(uint input) returns (uint)<br />
var compiled = web3.eth.compile.solidity(source);<br />
var Multiply7 = web3.eth.contract(compiled.Multiply7.info.abiDefinition);<br />
var multi = Multiply7.at("0x0ab60714033847ad7f0677cc7514db48313976e2")<br />
multi.multiply.sendTransaction(6, {from: "0xeb85a5557e5bdc18ee1934a89d8bb402398ee26a"})<br />
Register a callback which is called when the Print event created a log.<br />
multi.Print(function(err, data) { console.log(JSON.stringify(data)) })<br />
{"address":"0x0ab60714033847ad7f0677cc7514db48313976e2","args": {"":"21"},"blockHash":"0x259c7dc07<br />
See for more information the web3.js wiki page.<br />
Console<br />
The geth console offers a command line interface with a javascript runtime. It can connect to a local or remote<br />
geth or eth node. It will load the web3.js library that users can use. This allows users to deploy and interact with<br />
88 Chapter 1. Contents