1

I have full bitcoin node available through jsonrpc interface. How my app can detect if this node is in sync with the network?

1 Answer 1

5

Using the getblockchaininfo RPC command :

  • if initialblockdownload is true, your node is currently syncing with the network for the first time.
  • else :
    • if the headers field number is superior to the blocks field number, your node is catching up with the current state (likely after having been restarted)
    • else if the headers field number is equal to the blocks field number, your node is synced ! 🎉

Here is the current output of the command for me :

$ bitcoin-cli getblockchaininfo
{
  "chain": "main",
  "blocks": 634379,
  "headers": 634379,
  "bestblockhash": "000000000000000000136f1b78deeebc33a9b7b33d25c2e37f5446cb33b586fd",
  "difficulty": 13732352106018.34,
  "mediantime": 1591963775,
  "verificationprogress": 0.9999999385944023,
  "initialblockdownload": false,
  "chainwork": "0000000000000000000000000000000000000000104a35fae53a5b470d8e9524",
--snip--
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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