0

Assume i have the address of a contract, and now i would like to retrieve the information for its creation transaction. I used getCode(), but return bytecode for the contract, which is different. If i could get the hash of the creation transaction, i could easily retrieve its information.

Any idea of how to retrieve, at least, the hash of the transaction that created the contract, given only the address of the contract?.

1

Just get list of "normal" and "internal" transactions for contract address:

https://api.etherscan.io/api?module=account&action=txlist&address=0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae&startblock=0&endblock=99999999&page=1&offset=10&sort=asc&apikey=YourApiKeyToken

https://api.etherscan.io/api?module=account&action=txlistinternal&address=0x2c1ba59d6f58433fb1eaee7d20b26ed83bda51a3&startblock=0&endblock=2702578&page=1&offset=10&sort=asc&apikey=YourApiKeyToken

The very first transaction will most probably be the one that created the smart contract. See documentation for details.

Though it is possible that there were some ether transfer to contract's address before is was deployed.

  • Thanks.It helps me a lot. Although in some cases will not return the correct answer as you mentioned! – MWH Apr 10 at 16:43
  • Although this solution is good! it seems it is very slow. do you know a better way to only get the first transaction. what start and end block params should be? – MWH Apr 12 at 10:02
  • API supports paging, so you just need to use binary search to find the last non-empty page, I think. – Mikhail Vladimirov Apr 12 at 10:04
  • 1
    Oh, API has parameter sort=asc, you may try to play with it :) – Mikhail Vladimirov Apr 12 at 10:04

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.