I would like to get the block number given a timestamp in unix time using python, something like:
timestamp = 1438270214
block = get_block_number(1438270214)
>>>25
I would like to get the block number given a timestamp in unix time using python, something like:
timestamp = 1438270214
block = get_block_number(1438270214)
>>>25
You can get the block number by timestamp, using etherscan's API:
https://api.etherscan.io/api?module=block&action=getblocknobytime×tamp=1578638524&closest=before&apikey=YourApiKeyToken
Take a look at these links to see how this might work in code: 1, 2 and 3.
block_timestamp = last_block_number - ((now_timestamp - target_timestamp) / average_minig_time)or something like that. This gives you a very smaller range of blocks to loop-search until you get the desired one. Take a look at this discussion. – Rouhollah Joveini Mar 08 '22 at 12:12