ethereumweb3jsgo-ethereum

eth.getBalance() and eth.getBlock("latest").number returning 0


Following is the console output of the geth:

> eth.syncing
{
  currentBlock: 3935087,
  highestBlock: 3935168,
  knownStates: 6020785,
  pulledStates: 6015769,
  startingBlock: 3935060
}

The account address is:0x374A7fd1A537646652bc79Ad76B5D4e737373372 TxHash:0x9797923f033a454aac25a7c324b7f37030ebc013cc4f80d85414016653d2e1ab TxReceipt Status:Success Block Height:3934618 (576 Block Confirmations) TimeStamp: 2 hrs 23 mins ago (Feb-26-2019 02:32:42 AM +UTC)

From: 0x31b98d14007bdee637298086988a0bbd31184523To:0x374a7fd1a537646652bc79ad76b5d4e737373372 Value:7.5 Ether ($0.00)

> eth.blockNumber

0
> eth.getBalance("0x374a7fd1a537646652bc79ad76b5d4e737373372")

0

Now I am confused as already geth has synced upto block "3935087" but still unable to fetch state written in block "3934618".


Solution

  • Most likely your local state trie is still not synced. You have to consider that by default Geth is called in fast mode, therefore instead of starting from the genesis block and re-executing every txs in the history of the blockchain, it does only sync the block headers and reassembling them into a chain.

    Unfortunately, as you didn't replay the blockchain txs, the information included at the state trie such as nonces, balances, etc...will not be still available. Once you node download every block headers an link them it will trigger the next phase which downloads the txs included in each of the blocks and executes them in order in order to also sync your local state trie.

    If you are running on Ethereum mainnet that might take longer than a week, in case of the a TestNet, such as Rinkeby, it takes around 2-3 days.

    In my team, Lightstreams, we are working on implementing an in-house Ethereum compatible blockchain whose performances is 10x faster than official ethereum blockchain and it also provides much less cost per tx and ensures the finality of them. If you feel giving it a try we will be glad to onboard you on it. our open-sourced repo