Search code examples
ethereumweb3jsgo-ethereum

Ropsten network connection with web3.js(Version 1.0.0-beta.34)


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.


Solution

  • 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.