2

I have an serious issue, I'm trying to figure out since two days but not succeeded. I want to connect testnet ropsten using web3.js which I guess I'm successful but issue is I have some balance on ropsten network but web3.js displaying only 0.

You can check my address here it has some test 4.999873784 Ether: https://ropsten.etherscan.io/address/0x0346d2e50E29065b3b3c73B878FaFDcEb8Ee13f0

Here I will describe my flow (all links and ips are fake):

  1. First started geth

    geth --testnet --networkid 3 --rpc --rpcaddr "36.241.154.2" --rpccorsdomain "shahzad.com, http://shahzad.com, https://shahzad..com" --rpcapi="db,eth,net,web3,personal, account" 
    
  2. I included web3.js in my web page.

    //https://github.com/ethereum/web3.js
    <script src="http://shahzad.com/myapp/web3.js-1.0.0-beta.34/dist/web3.min.js"></script>
    
    <script type="text/javascript">
    //var Web3 = require('web3');
    var web3 = new Web3(new Web3.providers.HttpProvider('http://36.241.154.2'))
    
    $(function(){
    
    web3.eth.getBalance('0x0346d2e50E29065b3b3c73B878FaFDcEb8Ee13f0' , function(err, res){
        console.log("getBalance: "+res); //Displaying 0 //https://ropsten.etherscan.io/address/0x0346d2e50E29065b3b3c73B878FaFDcEb8Ee13f0
    
    });
    web3.eth.net.getId(function(err, res){
            console.log("Net: "+res); //Displaying 3
    });
    web3.eth.net.getNetworkType(function(err, res){
            console.log("getNetworkType: "+res); //Displaying ropsten
    });  
    web3.eth.getBlockNumber(function(error, result){
        console.log("Block Number: "+result); // Displaying 0
    })
    });
    

Additional steps taken:

eth.syncing
{
 currentBlock: 3069355,
 highestBlock: 3069421,
 knownStates: 27609511,
 pulledStates: 27597775,
 startingBlock: 3069303

}

What is wrong here any clue will be really appreciated.

Muhammad Shahzad
  • 9,340
  • 21
  • 86
  • 130
  • 1
    Your balance shows up correctly on my node, so your issue must be either with your node or with the `HttpProvider`. A couple things to try 1) confirm your connecting to the correct provider by outputting a debug call to `web3.eth.currentProvider` before your call to `getBalance`. 2) Are you using port 80 (or is this just part of your masking of IPs)? You don't have `--rpcport` specified and the default is 8545. 3) Does the correct network id show up in your console when you start `geth` (you don't need both `--networkid` and `--testnet`. Just use `--testnet`)? – Adam Kipnis Apr 20 '18 at 01:33
  • @AdamKipnis thank you, the issue was with my node it was not fully synced with so now I have equal number of currentBlock and highestBlock, can you please change your comment as answer? – Muhammad Shahzad Apr 20 '18 at 12:10

1 Answers1

2

The balance was showing up correctly through my local node and MetaMask, indicating an issue with OP's node. OP indicated via comments that once the node was fully synced (currentBlock == highestBlock), balance was showing correctly.

Note that in the post, the currentBlock was past the point where the transactions occurred, but the balance didn't show until fully synced. This is likely due to the state trie not yet being synced.

Adam Kipnis
  • 10,175
  • 10
  • 35
  • 48