0

I have contract address, and I want to find the block number, when it was deployed, to use it for loading events for this contract. Is it possible?

  • 1
    Why not just load events starting at block 0? – smarx Apr 10 '18 at 16:50
  • Do you have only address? if you have transaction hash, you can use function web3.eth.getTransactionReceipt – kherwa Apr 10 '18 at 16:52
  • @smarx I though I could optimize event loading by getting the deployment block number – Rob Yart Apr 11 '18 at 17:36
  • @kherwa Thanks, no I don't have txhash, otherwise it would be easy ;-) – Rob Yart Apr 11 '18 at 17:37
  • Have you measured the performance difference? I would guess that an extra API call to figure out the deployment block takes way more time than whatever penalty there is for starting from block 0. – smarx Apr 11 '18 at 20:24
0

You are possibly looking for something more progamatic. A good starting point is the idea that each contract starts with a deployment transaction. It's always the first transaction in the contract history.

On Etherscan

enter image description here

Hope it helps.

0

Assuming you know the transactionHash of the transaction which created your contract, you could just use the web3js function: web3.eth.getTransaction(transactionHash [, callback])

This will return you an object where you can access the block number you are looking for. Check this example code out!

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.