3

In etherscan each creation transaction has the contractAddress as 'to' value.

e.g.: https://etherscan.io/tx/0xe0ddfde8610cceae5b360c58a7c016b6654f838b8d820f290403d0c8d2cacfdc here: [Contract 0x85303e8e244b68a100308a59e1a008ff03a384b2 Created]

But actually RPC requests show that the Blockchain saves only "null" in this value in the transaction in the mined Block.

So How do etherscan know, which address the new contract has?

4

When a contract is created, its address becomes the sha3 hash of:

  • the sender's address
  • the nonce of the sender (the amount of transactions the sender has made at the time)

It is therefore possible to dynamically compute the address without getting it from the RPC.

Example Python code:

address = sha3(rlp_encode(creator_account, creator_account_nonce))[12:]

You can use the mk_contract_address function of pyethereum to do this

References:

https://github.com/ethereum/pyethereum/blob/782842758e219e40739531a5e56fff6e63ca567b/ethereum/utils.py

http://martin.swende.se/blog/Ethereum_quirks_and_vulns.html

| improve this answer | |

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.