0

I would like to query a range of blocks on the EOSIO mainnet which were created during a specific time span (for example, from unix time 1555500000 to 1555600000, which is around April 17-18, 2019). How do I find the numbers of the blocks created in that time span?

I see it's possible via getting various blocks with the REST API (/v1/chain/get_block), looking at the timestamp field of the responses, and performing a binary search for each of my two unix time borders. Is there a more straightforward way?

2 Answers 2

1

Looks like dfuse comes to the rescue.

The /v0/block_id/by_time endpoint can be used as follows (example from the link):

curl -H "Authorization: Bearer $TOKEN" \
    "https://mainnet.eos.dfuse.io/v0/block_id/by_time?time=2019-03-04T10:36:14.5Z&comparator=gte"

Have to convert Unix time to ISO8601 extended format, but that can be automated too.

1

When the blockchain operates normally, you get a new block every half a second. So you can start with any block you want and calculate the diff in seconds times 2 to get the number of blocks to diff from your initial query.

Might be off by just a few since tge real world is not mathematically precise, especially when dealing with time and networks.

2
  • 1
    Ideally 0.002*(d.getTime()-1528545389000) should give the latest block number (considering 1528545389000 is the timestamp when Block1 was generated) But it doesn't. Probably because BPs missed a lot of blocks on the way. So you need a source which knows about when these blocks were missed. You may consider the answer from @Gassa
    – mixdev
    Commented Sep 24, 2019 at 6:11
  • d=Date.now() BTW
    – mixdev
    Commented Sep 24, 2019 at 6:22

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.