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 />
was included and how much gas was used by the EVM. If a transaction creates a contract it will also contain the<br />
contract address. We can retrieve the receipt with the eth_getTransactionReceipt RPC method.<br />
> curl --data '{"jsonrpc":"2.0","method": "eth_getTransactionReceipt", "params": ["0x3a90b5face52c<br />
{"id":7,"jsonrpc":"2.0","result":{"transactionHash":"0x3a90b5face52c4c5f30d507ccf51b0209ca628c6824<br />
We can see that our contract was created on 0x6ff93b4b46b41c0c3c9baee01c255d3b4675963d. If<br />
you got null instead of a receipt the transaction has not been included in a block yet. Wait for a moment and check<br />
if your miner is running and retry it.<br />
Interacting with smart contracts<br />
Now that our contract is deployed we can interact with it. There are 2 methods for this, sending a transaction or<br />
using call as previously explained. In this example we will be sending a transaction to the multiply method of the<br />
contract.<br />
If we look at the documentation for the eth_sendTransaction we can see that we need to supply several arguments.<br />
In our case we need to specify the from, to and data arguments. From is the public address of our account<br />
and to the contract address. The data argument is a bit harder. It contains a payload that defines which method<br />
must be called and with which arguments. This is were the ABI comes into play. The ABI defines how to define<br />
and encode data for the EVM. You can read all the details about the ABI here.<br />
The bytes of the payload is the function selector and defines which method is called. This is done by taking the<br />
first 4 bytes from the Keccak hash over the function name and its argument types and hex encode it. The multiply<br />
function accepts an uint which is an alias for uint256. This leaves us with:<br />
> web3.sha3("multiply(uint256)").substring(0, 8)<br />
"c6888fa1"<br />
See for details this page.<br />
The next step is to encode the arguments. We only have one uint256, lets assume we supply the value 6. The ABI<br />
has a section which specifies how to encode uint256 types.<br />
int: enc(X) is the big-endian two’s complement encoding of X, padded on the higher-oder (left)<br />
side with 0xff for negative X and with zero bytes for positive X such that the length is a multiple of 32<br />
bytes.<br />
This encodes to 0000000000000000000000000000000000000000000000000000000000000006.<br />
Combining the function selector and the encoded argument our data will be<br />
0xc6888fa10000000000000000000000000000000000000000000000000000000000000006.<br />
Lets try it:<br />
> curl --data '{"jsonrpc":"2.0","method": "eth_sendTransaction", "params": [{"from": "0xeb85a5557e<br />
{"id":8,"jsonrpc":"2.0","result":"0x759cf065cbc22e9d779748dc53763854e5376eea07409e590c990eafc0869d<br />
Since we sent a transaction we got the transaction hash returned. If we retrieve the receipt we can see something<br />
new:<br />
{<br />
blockHash: "0xbf0a347307b8c63dd8c1d3d7cbdc0b463e6e7c9bf0a35be40393588242f01d55",<br />
blockNumber: 268,<br />
contractAddress: null,<br />
cumulativeGasUsed: 22631,<br />
gasUsed: 22631,<br />
logs: [{<br />
address: "0x6ff93b4b46b41c0c3c9baee01c255d3b4675963d",<br />
blockHash: "0xbf0a347307b8c63dd8c1d3d7cbdc0b463e6e7c9bf0a35be40393588242f01d55",<br />
blockNumber: 268,<br />
data: "0x000000000000000000000000000000000000000000000000000000000000002a",<br />
logIndex: 0,<br />
topics: ["0x24abdb5865df5079dcc5ac590ff6f01d5c16edbc5fab4e195d9febd1114503da"],<br />
1.7. Contracts and Transactions 87