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.

0

2 Answers 2

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 } */
1
  • Now-a-days, one should console.log("Syncing is " + await web3.eth.isSyncing()); and await web3.eth.getBlockNumber(). Jan 9, 2021 at 14:32
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
    }
    
1
  • 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, 2017 at 5:57

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