21

How to get information about the state of the blockchain on a geth node?

There are mentions of admin.chainSyncStatus in the documentation, but it is undefined on my 1.4.0 node. The admin.nodeInfo shows a hash for the head block, but not the number.

This information is sort-of available in the log, but that is not an answer.

redfish
  • 497
  • 1
  • 5
  • 9

2 Answers2

27

eth.blockNumber will give the most recent block your node has processed.

eth.syncing gives more information, like what the estimated highest current block is.

var sync = web3.eth.syncing; 
console.log(sync);
 /* { startingBlock: 300, currentBlock: 312, highestBlock: 512 } */
Tjaden Hess
  • 37,046
  • 10
  • 91
  • 118
12

You can use eth.blockNumber as shown below:

> eth.blockNumber
1486570

Source: Ethereum Wiki - JavaScript API.

Referring to @Tjaden Hess's answer,

  1. When geth has not started syncing yet:

    > var sync = web3.eth.syncing; 
    undefined
    > console.log(sync);
    false
    
  2. After geth has started syncing:

    > var sync = web3.eth.syncing; 
    undefined
    > console.log(sync);
    [object Object]
    undefined
    > sync
    {
      currentBlock: 1486592,
      highestBlock: 1488447,
      startingBlock: 1486592
    }
    
BokkyPooBah
  • 40,274
  • 14
  • 123
  • 193
  • Sometimes highestBlock returns: undefined maybe 100 times in a loop until it is able to return a valid number, is it normal? Please note that geth is syncing. @BokkyPooBah – alper Apr 19 '17 at 05:57