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
Using the getblockchaininfo
RPC command :
- if
initialblockdownload
istrue
, your node is currently syncing with the network for the first time. - else :
- if the
headers
field number is superior to theblocks
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 theblocks
field number, your node is synced ! 🎉
- if the
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--
}