AnswerBun.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!

Related Questions

Nethereum C# FilterInput.GetAllChanges always empty

1  Asked on February 12, 2021 by exaltedoil

       

Testing Gas Token on testnet failing transaction

0  Asked on February 9, 2021 by marr

   

I am unable to install web3 on my mac

1  Asked on February 5, 2021 by saiteja-kuruva

 

Out of stack DUP2 1/1024 when adding string to parameter

0  Asked on February 1, 2021 by koukotsu

   

How to find contract’s address?

6  Asked on January 31, 2021 by user3280964

   

Import error in Truffle Pet Shop tutorial

1  Asked on January 29, 2021 by xpain

   

Timeout w/ Mocha on deploying a contract

2  Asked on January 26, 2021 by tulun

   

How to send ERC20 token to smart contract in constructor

1  Asked on January 24, 2021 by user938363

 

Deploy bytecode

1  Asked on January 19, 2021 by william-entriken

   

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP