10

Ideally the solution would use web3, but other solutions are acceptable.

Motivation:

Event lookups can be passed fromBlock field. If I know the block a contract was created, I can more accurately do an event lookup (rather than searching the whole chain)

  • What exactly are you looking for? Could you extend your question a little bit and maybe add, what you have tried so far? What about the timestamp of the transaction to deploy the contract? – soc1c Feb 6 '16 at 21:54
  • @5chdn in this question I don't have access to the transaction id, only the contract address. I added a little bit about the motivation. – Aakil Fernandes Feb 7 '16 at 0:33
8

The consensus blockchain doesn't contain any easily queryable information to figure out the creation time of a contract based solely on its address. If you have the hash of the transaction that created the contract, retrieving that would give you back the block number too.

If you need only to occasionally figure out the creation block of a/some contracts, you could also consult a block explorer for the first transaction.

However, although finding events belonging to a contract in the entire chain is obviously slower than searching from only a known starting block, event queries use mip-mapped bloom filters, so they should be relatively fast at the current chain size. The canonical solution is to create a filter from block 0 initially, and then store away the block number until which you already processed the blocks and only continue from there the next time.

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.