2

我有一个严重的问题,两天以来我一直在尝试解决,但没有成功。我想使用 web3.js 连接 testnet ropsten,我想我成功了,但问题是我在 ropsten 网络上有一些平衡,但 web3.js 只显示 0。

你可以在这里查看我的地址,它有一些测试 4.999873784 Ether: https ://ropsten.etherscan.io/address/0x0346d2e50E29065b3b3c73B878FaFDcEb8Ee13f0

在这里我将描述我的流程(所有链接和ips都是假的):

  1. 首先开始 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. 我在我的网页中包含了 web3.js。

    //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
    })
    });
    

采取的其他步骤:

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

}

这里有什么问题,任何线索都将不胜感激。

4

1 回答 1

2

余额通过我的本地节点和 MetaMask 正确显示,表明 OP 的节点存在问题。OP 通过评论指出,一旦节点完全同步(currentBlock == highestBlock),余额显示正确。

请注意,在帖子中,currentBlock已经过了交易发生的时间点,但余额直到完全同步后才显示。这可能是由于状态树尚未同步。

于 2018-04-20T20:14:49.813 回答