7

Is it possible to find out in which block a contract was created using web3?

2

If you have the transaction hash that created the contract, do a web3.eth.getTransactionReceipt(*hash*). The resulting object will contain a blockNumber.

You can make sure that this is the creation hash by checking whether contractAddress in the object is populated with your contract's address (to should be empty).

  • 2
    What if you don't have the txhash? – 0xcaff Aug 14 '17 at 6:07
  • 1
    is this on the public chain? – Joël Aug 14 '17 at 6:07
  • 3
    Yes. I know I can look on a site etherscan to find this information, but I want to do it programatically. – 0xcaff Aug 14 '17 at 6:09
  • 1
    What if I'm analyzing contracts I didn't deploy? How does etherscan do it? – 0xcaff Aug 14 '17 at 6:13
  • 1
    I meant contracts which were deployed by other parties. – 0xcaff Aug 14 '17 at 6:14

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.