TransWikia.com

why web3.eth.getBlockNumber().then(console.log) returns 0

Ethereum Asked by Shifted Five on December 9, 2020

I have build a Ethereum Full Node in Ubuntu 18.04. geth is running through the following command:

nohup geth --rpcaddr 127.0.0.1 -rpcport 8545 --rpc -rpcapi "wb3,admin,eth,personal,net" --ws --wsaddr 127.0.0.1 --wsport 8546 --wsorigins "*" --datadir "/data/ethereum" --syncmode fast --maxpeers 10000 --cache 8196 >> geth.log 2>&1 &

one line of geth.log content:

INFO [06-06|00:59:22.250] Imported new block headers               count=1    elapsed=6.793ms     number=10206927 hash="92683d…04062d"

truffle is configured as the following:

development: {
     host: "127.0.0.1",     // Localhost (default: none)
     port: 8545,            // Standard Ethereum port (default: none)
     network_id: "*",       // Any network (default: none)
    }

In truffle console, when I use command web3.eth.getBlockNumber().then(console.log), it just returns

0
undefined

Why is it not 10206927(from geth.log) or a close number?

Thanks in advance!

2 Answers

In the case your node is syncing, then do:

   this.web3.eth.isSyncing((error: Error, sync: any) => {
        if (!error && sync) {
            console.log(sync.currentBlock);
            console.log(sync.highestBlock);
        }
    });

Answered by msp on December 9, 2020

maybe the web3.eth.getBlockNumber().then(console.log) returns 0 because geth has not yet starterd the block synchronization but only the headers import.

When the import of the headers will be completed and the blocks sync will start, the web3.eth.getBlockNumber().then(console.log) probably will return a non-zero value.

Hope this helps.

Answered by Gabriele Del Monte on December 9, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP