I guess if we start doing mathematical calculation then we can easily find exjact block no which was formed just before difficulty was adjusted. But is there anyway around like by using RPC by which we can find it out?


I don't know a way to get this directly through the RPC without looking at multiple blocks and comparing them, but the math formula is easy:

floor(current_number_of_blocks / 2016) * 2016 - 1

The floor function rounds a number down to an integer value; it's available in most programming languages, although it's sometimes named something to do with integers (e.g. int()). The number 2,016 is the number of blocks in a retarget period (the time between difficulty changes).

Here's an example command:

bitcoin-cli getblockchaininfo | jq '.blocks / 2016 | floor * 2016 - 1'

As requested, as of this writing, block 524,159 is the last block before the difficulty change. To get the first block with the new difficulty, remove the -1 (so block 524,160 in this example).

The command used in the above example is jq.

  • 2
    Alternatively, blocks - (blocks % 2016) - 1. – Nate Eldredge May 24 '18 at 19:51

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.