I am in need of a library that estimates a date or some sort of timestamp when fed with a future block number (on mainnet or any major testnet).

For instance, https://etherscan.io/block/countdown/9950000 shows up like this:

Etherscan Countdown

Unfortunately, I emailed Etherscan and the countdown feature is not available in their API (I probably could reverse engineer it by parsing the HTML response, but seems overkill).

Is there any library that does this?

  • Why don't you get the average block time interval from an API and then just calculate it by yourself ? What's the problem with this solution ?
    – Laxmana
    May 25 '19 at 17:36
  • @Laxmana yeah I already did something like that, but my implementation's buggy and just thought to ask if the community knows any library. May 25 '19 at 17:53
  • I see. I don't know any library providing that functionality. Maybe we can help with the code :).
    – Laxmana
    May 25 '19 at 17:57
  • Haha thanks, but drafting the question helped me fix the bugs! Maybe I'll find time to make a PR to web3 or ethers.js to add this estimation feature. May 25 '19 at 18:00
  • That's good! Good luck!
    – Laxmana
    May 25 '19 at 18:08

You can do this with web3.js - web3.eth.getBlock will return the block info containing the timestamp of the block

  • 1
    Yes, for past blocks, but what about future blocks? You need to estimate based on the most recent information regarding block times. May 25 '19 at 16:40
  • get the last block and 1000 or 10000 blocks before the last one, divide the timedifference to the number of blocks and you will get the average block time for future estimations
    – KNK
    May 25 '19 at 16:57
  • I already have a back-of-the-napkin implementation for that, but a library or an API would be far more accurate and faster than I could be. May 25 '19 at 16:59
  • Nothing can be more accurate that use the last mean of the interval and calculate the number you are asking for. Nothing in the world and beyond. Why should I create a library for a y=mX+C calculation?
    – Rick Park
    May 6 '20 at 21:50

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.