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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.