1

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!

1
  • 1
    That's a bit odd, you could try the same and check with the geth console
    – Stephen S
    Commented Jun 5, 2020 at 19:29

2 Answers 2

2

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.

1

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);
        }
    });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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