Why is geth always returning a 0 balance?

  • I installed geth on a remote server (Ubuntu 14.04) and created an account. I transferred 0.01 eth to the account. From my local machine (OS X), I can view the transaction and account balance correctly with web3.

    However, if I log into the server and try to get the balance, it returns 0. In fact, trying to check the balance, or get info on anything returns 0. It's almost like my node is not connected, by it says I have 8 peers (and I've listed them and they look legit).

    To recap, running the following on my home computer returns "0.01":

    web3.fromWei(web3.eth.getBalance('0x7cacf18f931259c30a7194fa96ab3a44c38b3535'),'ether').toString(10)
    

    As of this writing, that is correct.

    However, running the same command, or even web3.eth.getBalance(web3.eth.coinbase) always returns 0 on my server. In fact, trying to get info on anything on the public chain fails (including contracts).

    I'm trying to get a simple Dapp deployed, but getting a node up and running is driving me crazy!

    For reference, I have ethereum/geth v. 1.3.3 installed. I've also tried 1.4-unstable. I've tried a variety of methods to start geth, and have no idea why it can't get info from the public chain.

  • linagee

    linagee Correct answer

    5 years ago

    It sounds like geth is not yet synced up.

    Please type this into your geth console:

    eth.getBlock("latest").number
    

    As of this post, you should get 894332 or higher.

    I get the correct output on my geth console.

    > web3.fromWei(web3.eth.getBalance('0x7cacf18f931259c30a7194fa96ab3a44c38b3535'),'ether').toString(10)
    "0.01"
    

    Ok, that might be the issue. Right now the latest block is `253737`

    Definitely the issue. I checked and I see your transaction was in block 894138. So you need a larger latest block than this before it will appear. Please mark question as answered if this satisfies the question.

    Thanks, makes sense. Didn't realize it took so long to sync. I'll mark this correct after the 5 min waiting period.

    If it's slow to sync, please start geth using the --fast option. (This will make it sync faster if you have the latest version of geth.)

License under CC-BY-SA with attribution


Content dated before 7/24/2021 11:53 AM