16

This question already has an answer here:

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.

marked as duplicate by eth May 12 '16 at 8:35

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

21

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 } */
9

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
    }
    
  • 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 5:57

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