I understand from HIP-415: Introduction Of Blocks, that Hedera now has blocks, and they're based on timestamps of the transactions being grouped together into "record files" which are an artefact of how they are ingested into the Hedera mirror nodes (from the Hedera consensus nodes). Essentially all transactions that are inside the same record file are considered to be in the same block as well, and these blocks are produced approximately every 2 seconds.
Is there a way that I can convert a date (timestamp) into a block number?
My objective is to be able to invoke eth_getBlockByNumber
,
and I need work out the first parameter for that RPC request
based on timestamp.
curl -s -X POST \
-H 'Content-Type: application/json' \
-d '{"jsonrpc":"2.0","id":"2","method":"eth_getBlockByNumber","params":[MY_BLOCK_NUM, false]}' \
http://localhost:7546
(Need to work out MY_BLOCK_NUM
in the ^ command above.)
For example, here's block 4507206,
which corresponds to the record file 2023-05-10T08_27_52.012122604Z.rcd.gz
,
and contains all transactions between
08:27:52.0121
and 08:27:53.7004
in UTC today.
Suppose I did not know both what the block number was,
or what the record file was.
I only have a single timestamp,
and I want to find the corresponding block number from it.
How can I do this (programmatically)?