Is it possible to get a block by timestamp?

0

I use Bitcoin Core API and I can retrieve a block by header hash as parameter using the getblock method. I need to get a block by given timestamp (median time).
I found some solution.

difference_in_blocks = round((last_block_mediantime - given_timestamp) / 600sec)
desired_block = last_block_heigth + 1 - difference_in_blocks

600 seconds - average time of a block mining (I assume this value is a constant)

Is there a specific API method or a better, more accurate way to do this, than my solution?

March Cat

Posted 2019-03-14T20:19:52.203

Reputation: 1

No answers