testnets ropsten – web3.eth.getBalance(‘address’) always returns zero

ropstentestnets

Am trying to deploy a contract to "Ropsten Testnet" network. I have an account to which i have managed to transfer 6 ethers through faucet. My account's "ETH Balance" shows 6 ethers, from site https://ropsten.etherscan.io/address/. But web3.eth.getBalance('address') for some reason still gives me a zero balance on truffle console.

I am therefore not able to deploy my Contract to "Testnet".
I get an error as:

Error encountered, bailing. Network state unknown. Review successful transactions manually.
Error: insufficient funds for gas * price + value

Below is my geth command.

geth --testnet --syncmode "fast" --rpc --rpcapi db,eth,net,web3,personal --cache=1024  --rpcport 8545 --rpcaddr 127.0.0.1 --rpccorsdomain "*" --bootnodes "enode://20c9ad97c081d63397d7b685a412227a40e23c8bdc6688c6f37e97cfbc22d2b4d1db1510d8f61e6a8866ad7f0e17c02b14182d37ea7c3c8b9c2683aeb6b733a1@52.169.14.227:30303,enode://6ce05930c72abc632c58e2e4324f7c7ea478cec0ed4fa2528982cf34483094e9cbc9216e7aa349691242576d552a2a56aaeae426c5303ded677ce455ba1acd9d@13.84.180.240:30303"

Not sure why the 6 ethers are not reflecting on my personal account balance.

Best Answer

Is your node fully synced? I guess this is the main reason why your eth balance is 0. The balance will be zero unless you sync to the block in which you received test ethers.

In order to deploy the contract, you could use MyEtherWallet and Remix. Steps for the same are quite simple.

  • Compile your code from remix online solidity compiler. Copy the bytecode from here.
  • Open my ether wallet. Go to Contracts--> Deploy contract.
  • Choose the network to Ropsten from top-right corner.
  • Paste the bytecode and unlock you wallet using any of the provided methods and deploy the contract.

Else you can also use Remix with Metamask for the same. Import your account to metamask and deploy contract directly from remix.

Update:

How to know if your blockchain is synced ?

You can check whether your node is syncing by:

eth.syncing

If your node is not syncing eth.syncing returns false. Else it returns output like

{ currentBlock: 10000, highestBlock: 1822434, knownStates: 1, pulledStates: 0, startingBlock: 90 }

This means you have downloaded 10000 blocks where total blocks are 1822434.

You can check the block in which you received the ether balance by the transactionHash. If you have transaction hash you can use eth.getTransactionReceipt(txHash) to check the block in which your transaction was included. If you have downloaded the blockchain upto that block then your balance will appear. Note: If you are using fast sync, you may have to wait till complete node is in sync to see your balance not only syncing till the block in which your transaction was included.

Related Topic