2

I am new to the Ethereum blockchain and web3.py, and I'm interested in finding a way to work with a contract address to return the block and transaction hashes for the block where the contract was deployed.

I've been working with the getCode() method that's part of web3.py, but have ran into a wall. My idea is to use the block_identifier argument in some way to improve upon a sequential search of all blocks in the chain, but don't quite know the best approach.

Is there any way to utilize the getCode() method to accomplish my overall goal of returning the block and transaction hashes?

Any help or hints would be greatly appreciated. This is an assignment, therefore I'm not looking for the complete answer, just some help to get moving again.

1

This command

getBlock (getState --no_header --parts deployed 0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359 | cut -f4) --uniq_tx

from Trueblocks (my project) produces these results:

bn      tx      addr                                        reason
---------------------------------------------------------------------
988725  99999   0xf8b483dba2c3b7176a3da549ad41a48bb3121069  miner
988725  0       0x2910543af39aba0cd09dbb2d50200b3e800a63d2  from
988725  0       0xb69f747788d0911bb798dccb7572a7d14a67d31f  to
988725  1       0xd1220a0cf47c7b9be7a2e6ba89f429762e7b9adb  from
988725  1       0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359  creation
988725  1       0x0000008352600160a060020a0333811660048501  input

The deployment of the address (labeled as creation here) appears at transaction 988725.1 which, with this command, returns the hash:

getTrans 988725.1

producing

0x2f121b55188e408a274a11e3d59648f8a71a5be99f830576be350448aa5012f3

You can, of course, stick in your own address. You do have to be running your own node or have an Infura API key for it work.

0
  1. Ethereum state machine is "key-value" DB. Ethereum state machine use contract address as the "key" value. "value" is contract balance, nonce, contract byte code, variables.

so, block hash and transaction hash can't be obtained.

  1. getcode() returns contract byte code.
  • Thank you for the information. I've figured out how to find the block where a contract was deployed using the getCode() method, but I'm now having issues with finding the transaction hash for the deployment of the contract. – BryantV90 Jun 4 '19 at 0:06

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.