W3Schools



我正在同步一个新节点。我怎样才能知道最新的块是什么让我知道我要走了多远?

nodessynchronization
9个回答
5

以太坊钱包 will display the latest block number. The official 以太坊统计 website also displays it. (Note: this doesn't represent all peers on the network.)


7

您可以使用块浏览器,例如Etherchain.


12

如果你使用Geth:

停止你当前的geth实例,然后用它重新运行它console argument:

geth console

然后输入:

web3.eth.blockNumber

它会给你块号作为整数,这是功能文档. If you are looking for the block hash instead you can use:

web3.eth.getBlock(BLOCK_NUMBER).hash

所以对于当前块(atm),它将是:

web3.eth.getBlock(887893).hash

并为最新的块:

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

35

对于Geth,在另一个终端中,附加到Geth控制台,例如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.

在控制台中,运行eth.syncing

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

然后,您可以看到您所在的位置(currentBlock),以及您仍需要访问的块(highestBlock)。 (它们之间的差异是你剩下的块数。)

你可以跑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.


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

如果您仍在同步,则可以键入eth.syncing并报告

  • currentBlock
  • highestBlock
  • startingBlock

如果eth.syncing为false,则使用sebastian提到的eth.blockNumber命令,并将其与您最喜爱的在线块浏览器报告的块高度进行比较


1

web3.eth.getBlock( '最新')然后(函数(X){的console.log(x.timestamp)})。


0

我很生气,因为eth.syncing returns false even before the syncing starts (and it also returns false after the sync , so there's no way to tell).

不同的方法,如果您不需要实际的块编号:您可以将最新的同步块的时间戳与当前时间进行比较:

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

如果这个数量大于,比如2分钟(120), then it's very likely that you don't have the last blocks.