Skip to content

Latest commit

 

History

History

obtain-block-number-from-timestamp

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Obtain "block" number based on timestamp

  • Get the timestamp in seconds since UNIX epoch that you wish to find the block for, using date.
  • Make a "list blocks" (/api/v1/blocks) API request to Hedera mirror nodes, with the following query params:
    • timestamp=gte:${TIMESTAMP}: This will find all blocks that have been created after the specified timestamp.
    • order=asc: This is to list blocks in order of increasing timestamp.
    • limit=1: This will restrict the results returned to be only one block.
    • When these query params are used in combination, the result will contain only the first block that occurs after the specified timestamp.
  • Convert the block number from decimal to (base 10) to hexadecimal (base 16).
  • Make an eth_getBlockByNumber JSON-RPC request to an instance of hedera-json-rpc-relay specifying this block number.

Code

The file obtain.sh in this directory demonstrates the above.

References