2

I am currently trying to deploy a smart contract with bytecode in a private Ethereum chain, using the "dev" chain of the parity client. For this, I compiled the following contract:

pragma solidity ^0.4.11;

contract MyContract {
    uint i = (10 + 2) * 2;
}

with solidity:

solc --bin test.sol 

======= test.sol:MyContract =======
Binary: 
    608060405260186000553480156014576     
    00080fd5b5060358060226000396000f3006080604052600080fd00a165627a7a72305820d0cc3f28b74510b6f3f34e1a1e1303c584b355320f387a3e30022117e3554e220029

I then used the following rpc call to create the transaction:

Request: {"method": "personal_sendTransaction", "id": 1, "jsonrpc": "2.0", "params": [{"from": "0x0053b6a9527c2ba72cf44486dd12d9930ce25bae", "data": "0x60806040526018600055348015601457600080fd5b5060358060226000396000f3006080604052600080fd00a165627a7a72305820d0cc3f28b74510b6f3f34e1a1e1303c584b355320f387a3e30022117e3554e220029"}, "test"]}.

where 0x0053b6a9527c2ba72cf44486dd12d9930ce25bae is an account on the private Chain which has ether and the passphrase test.

This is the answer I get:

Response: {"jsonrpc":"2.0","result":"0xf547c28a3f51c05832fadd4b807f5bb769196970d08e446b2644a2ea94359572","id":1}.

But the byte string given in result is not a valid address. How do I get the address of the contract I created?

4

The result you got is the "transaction hash" ( tx ), which you can then pass to a "eth_getTransactionReceipt" call in order to get the actual contract address.

See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_gettransactionreceipt

// Example Call / Request 

curl -X POST --data'{"jsonrpc":"2.0","method":"eth_getTransactionReceipt","params":["0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238"],"id":1}'

// Result
{
    "id":1,
    "jsonrpc":"2.0",
    "result": {
         transactionHash: '0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238',
         transactionIndex:  '0x1', // 1
         blockNumber: '0xb', // 11
         blockHash: '0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b',
         cumulativeGasUsed: '0x33bc', // 13244
         gasUsed: '0x4dc', // 1244
         contractAddress: '0xb60e8dd61c5d32be8058bb8eb970870f07233155', // or null, if none was created
         logs: [{
             // logs as returned by getFilterLogs, etc.
         }, ...],
         logsBloom: "0x00...0", // 256 byte bloom filter
         status: '0x1'
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.