2

I know that in the transaction receipt I can get the contract address by getting a transaction receipt from a generated transaction.

But I am wondering since smart contract addresses are deterministic in some sense if there is a way to predict the address from the transaction its self, not the receipt.

1

Ok, I actually found the answer my self sadly things are not updated in the documentation at least so far, however, there is a creates field in every transaction.

So when you, for example, do getBlock and get all blocks including transactions you can find if it was a contract creation transaction first by checking if to is zero which is mentioned in the documentation and creates as the address.

  • Can you leave a reference to documentation or json example. – medvedev1088 Nov 30 '17 at 12:42
  • 1
    contract address is contained in the receipt of the transaction: eth.getTransactionReceipt(hash).ContractAddress – Nulik Jun 29 '18 at 22:37
  • @Nulik your answer is not correct. I don't want it from the transaction receipt – Moe Elsharif Sep 4 at 11:39
1

@Nulik has the answer that is the clearest.

The only caveat is the actual command is eth.getTransactionReceipt(hash).contractAddress

If you are using Web3, use web3.eth.getTransactionReceipt(hash).contractAddress.

(Info on how to use Web3 in Python)

  • The whole point is getting the address without getTransactionReceipt so its not the right answer at all "I know that in the transaction receipt I can get the contract address by getting a transaction receipt from a generated transaction." Read the question clearly next time – Moe Elsharif Sep 4 at 11:37
  • @MoeElsharif Sorry...you are right. If you know the transaction creator address and the next nonce used (would have to be non-random), you can predict the next contract address. There is a CTF at this link -- blockchain-ctf.securityinnovation.com/# -- called TrustFund whose challenge is just this. But see slack-files.com/T0J0350JF-FK5NTH41J-d83c8daf88 for an example of how to see this information in Etherscan. – Daniel Connelly Sep 4 at 18:57
  • @MoeElsharif By the way, I think what was confused me was your best answer to your question, which doesn't seem to answer your question either. In your question you are asking "[is there] a way to predict the address from the transaction its self" (i.e., predicting addresses). Then in your answer, you are explaining how you can find the contract address of an already existing contract through the getBlocks function... Perhaps you forgot (both before and now) what your question really was. – Daniel Connelly Sep 4 at 19:32
0

You can actually get the contract address before a transaction is generated. A contract's address is determined by the address and nonce of the contract creator.

From the source code:

func CreateAddress(b common.Address, nonce uint64) common.Address {
    data, _ := rlp.EncodeToBytes([]interface{}{b, nonce})
    return common.BytesToAddress(Keccak256(data)[12:])
}

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.