37

I'm syncing up a new node. How can I find out what the latest block is so that I know how far I've got to go?

  • I have started to sync since 15 days ago and today I think I passed the highest block 4741144 I downloaded 4741185 of 4741144 but ethereum node started to downloaded chain data. does anybody know how many chain structure needs to download to full sync. my computer already downloaded about 10 M chain structure after reaching to highest block. – Farhad ghanaatgar Dec 16 '17 at 8:38

10 Answers 10

37

For Geth, in another terminal, attach to the Geth console, such as geth attach. This will allow you to keep your syncing node running, without restarting, and you will not see the noisy logs as you would if you simply ran "geth console" without other parameters.

In the console, run eth.syncing

> eth.syncing
{
  currentBlock: 745600,
  highestBlock: 889152,
  startingBlock: 745553
}

You can then see where you are (currentBlock), and the block you still have to reach (highestBlock). (The difference between them is the number of blocks you have left remaining.)

You can run eth.syncing a few times to check your progress, and it will return false when done. You can then use eth.blockNumber and also compare with a blockchain explorer, as other answers here mention.

  • 2
    Thanks for the answer, just note that geth attach doesn't work if you have the --mine flag specified (for test chains) so if you use that you should also probably use a mining script – makevoid Jan 23 '16 at 5:42
  • 1
    I use geth version 1.4.6 and eth.syncing just returns true or false. What's the new version of the eth.syncing command? – TMOTTM Jun 18 '16 at 17:11
  • @TMOTTM It might be a bug and I suggest "New issue" at github.com/ethereum/go-ethereum/issues – eth Jun 19 '16 at 6:48
  • more info was added to the output but this is still a valid way to check. – Rostol Jun 11 '17 at 16:57
  • Function web3.eth.isSyncing() will return false also when syncing has not yet started (or is currently not running). So one cannot rely solely on this function in order to determine the status of the Ethereum client. As you mentioned, probably need to combine the results of web3.eth.getBlockNumber() and a blockchain explorer into the decision-making. – goodvibration Jun 21 '18 at 15:13
17

If you are using Geth:

geth attach http://host

then enter:

web3.eth.blockNumber

It will give you the block number as integer, here's the function documentation. If you are looking for the block hash instead you can use:

web3.eth.getBlock(BLOCK_NUMBER).hash

so for the current block (atm) it will be:

web3.eth.getBlock(887893).hash

and for the latest block:

web3.eth.getBlock(web3.eth.blockNumber).hash

In the latest version of web3 you can use getBlockNumber() which returns a promise (thx @PaulRBerg for mentioning that)

  • 2
    I added an answer because simple re-run with "geth console" will have noisy logs interfering with the console; and eth.syncing provides more info. – eth Jan 22 '16 at 22:08
  • In versions 1.0.0 and above, blockNumber has been renamed to getBlockNumber and it returns a promise. – Paul Razvan Berg Jul 29 '18 at 15:24
7

You could use a block explorer, such as Etherchain.

6

there are 2 usefull scripts in https://github.com/lyricalpolymath/Ethereum-Scripts

with geth running, copy and paste this code in a terminal window to have a simple feedback of the blockchain syncing progress

geth --exec 'var s = eth.syncing; console.log("\n------------ GETH SYNCING PROGRESS\nprogress: " + (s.currentBlock/s.highestBlock*100)+ " %\nblocks left to parse: "+ (s.highestBlock-s.currentBlock) + "\ncurrent Block: " + s.currentBlock + " of " + s.highestBlock)' attach

you will get an output like this

------------ GETH SYNCING PROGRESS 
progress: 81.9161292631709 % 
blocks left to parse: 368837 
current Block: 1670754 of 2039591

download the script and with geth running, copy and paste this code in a terminal window to have a simple feedback of the blockchain syncing progress

geth --exec "loadScript('GethSyncingProgress_2TimeEstimate.js')" attach

will give you an output like

------------ GETH SYNCING PROGRESS - Time estimate
progress: 83.83513931320763
Estimated Time left*: 7d :11h :4m :4s.3
Time it took to parse 10 blocks: 0d :0h :0m :19s.5
blocks left to parse: 330536
  • Combine this with watch to get an updating feed: watch -n 10 "geth --exec 'var s = eth.syncing; console.log(\"\n------------ GETH SYNCING PROGRESS\nprogress: \" + (s.currentBlock/s.highestBlock*100)+ \" %\nblocks left to parse: \"+ (s.highestBlock-s.currentBlock) + \"\ncurrent Block: \" + s.currentBlock + \" of \" + s.highestBlock)' attach" – osolmaz May 29 '18 at 3:51
5

The Ethereum wallet will display the latest block number. The official Ethereum stats website also displays it. (Note: this doesn't represent all peers on the network.)

  • Note: It's 'mist browser' or 'ethereum wallet'. But there is no such thing as a 'mist wallet'. :) – Waqar Lim Aug 11 '16 at 10:18
  • stats.ethdev.com doesn't respond – Lu55 Oct 25 '17 at 16:32
  • I fixed the link. – paulmorriss Nov 15 '17 at 11:30
3

web3.eth.blockNumber gets you the latest block height on your node. Note that you have to have a synced node for that. When you are still downloading the blockchain this number will be smaller.

2

If you are still syncing you can type eth.syncing and it will report

  • currentBlock
  • highestBlock
  • startingBlock

If eth.syncing is false then use the eth.blockNumber command sebastian mentioned and compare it to the reported block height from your favorite online block explorer

  • so syncing===false doesn't guarantee that geth is in sync? if you provide an example of an online block explorer and how to retrieve the reported block height from it, I'll upvote your answer – knocte May 24 '16 at 8:30
  • I guess this one will do testnet.etherscan.io – TMOTTM Jun 19 '16 at 12:22
1

web3.eth.getBlock('latest').then(function(x){console.log(x.timestamp)});

0

I was annoyed because eth.syncing returns false even before the syncing starts (and it also returns false after the sync finished, so there's no way to tell).

A different way to go about it, if you don't need the actual block number: you can compare your latest synced block's timestamp with the current time:

Date.now()/1000 - eth.getBlock('latest').timestamp

If this amount is greater than, say, 2 minutes (120), then it's very likely that you don't have the last blocks.

0

I use the JSON RPC to check from another machine (assuming access). Replace 0.0.0.0:8545 with th RPC address and port of the machine running GETH with RPC.

curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":67}' 0.0.0.0:8545

returns

{"jsonrpc":"2.0","id":69,"result":{"currentBlock":"0x767811","highestBlock":"0x767879","knownStates":"0x8ba1951","pulledStates":"0x8ba0752","startingBlock":"0x5a95a1"}}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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