For some context, I'm writing software to index blockchain data for a dApp I'm creating. It basically uses ETH RPC calls to get eth logs, parses them, inserts into a DB, and updates checkpoints.

I use eth_logs to get logs for past blocks, and it works fairly quickly. However, I need to get the timestamp associated with each piece of data. Since eth_logs doesn't return any timestamp, I find myself calling eth_getblock and getting the timestamp from that. This is extremely, extremely slow (like 50x + slower once adding this). It's very inefficient cause you basically have to get every single block; eth_getblock returns transactions and everything. It doesn't seem reasonable to have an indexer running for days longer just to get timestamps.

Is there any more efficient way of getting timestamps associated with eth logs that anyone is using? One solution is to maintain a proprietary DB that has a mapping from block number to timestamp, that way you only have to index everything once and can reuse it. However it doesn't seem reasonable for everyone who needs this functionality to maintain their own DB. Wondering if others have ran into this inefficiency, and gotten around it.

  • Setting eth_getBlockByHash second parameter to false will return a list of transaction hashes. In any case I'd keep a cache of blocks headers so I don't have to call eth_getBlockByHash just to get the timestamp. Another option is to store the blockHash with the logs and fill the correct timestamp by running an aggregation query.
    – Ismael
    Commented Jun 12, 2022 at 21:33

2 Answers 2


Just stumbled on your question

It is not a directly actionable answer for your problem, but the best way forward in my opinion is to improve ethereum nodes to provide the timestamp info as part of the log as this is available to them.

See proposal : https://ethereum-magicians.org/t/proposal-for-adding-blocktimestamp-to-logs-object-returned-by-eth-getlogs-and-related-requests/11183

  • You can enable /graphql GoEthereum endpoint and fetch timestamps for all block numbers fast.

  • /graphql method is about 50x faster than eth_getBlock

  • Store the block hash -> timestamp map in memory

  • See the Python source here for the example code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.