Railway
Railway

Reputation: 71

eth.getBalance() always returns 0 in testnet

I am developing ethereum wallet api. For now, I want to get the balance for specific address by using eth.getBalace().

I run testnet following

alias geth = 'geth --ipcpath /home/tom/.ethereum/testnet/geth.ipc'
geth console

At this time, I can see the eth.syncing is true. And I sent 3 ether in http://faucet.ropsten.be:3001/. But I can get balace by using eth.getBalance() method.

When I check the http://etherscan.io, there is success status. And it is also showing in http://myetherwallet.com.

How can I get balance in my local?

Upvotes: 2

Views: 3994

Answers (1)

Adam Kipnis
Adam Kipnis

Reputation: 11001

The balance is 0 because you’re not connecting to the correct network when starting geth. The --ipcpath just tells geth where to store the IPC file when other local processes want to connect to your node. You need to specify the --testnet option to connect to Ropsten. It looks like you want to use the coinbase account for checking your balance, so you should also pass in your address with the --etherbase option.

alias geth = 'geth --ipcpath /home/tom/.ethereum/testnet/geth.ipc --testnet --etherbase \'YOUR_ADDRESS_HERE\''

To confirm you're connecting to the correct network, you should see something like this in your geth output:

INFO [02-05|11:33:45] Initialising Ethereum protocol versions="[63 62]" network=3

(Note - network=3 is Ropsten)

You can get the full list of geth commands here.

Once geth starts, you'll also have to wait for your node to sync in order to get your balance.

Upvotes: 1

Related Questions