ethereum - Ropsten与web3.js的网络连接(版本1.0.0-beta.34)

标签 ethereum web3js go-ethereum

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

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

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

  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

}

这里出了什么问题,任何线索都将非常感激。

最佳答案

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

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

关于ethereum - Ropsten与web3.js的网络连接(版本1.0.0-beta.34),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49929320/

相关文章:

python - 使用web3.py查询远程以太坊节点时出现间歇性 "Read time out"错误

ethereum - 如何查看Truffle支持的最新Solidity版本

blockchain - 如何将一系列结构从 web3js 发送到 Solidity 合约?

reactjs - 出现错误 : TypeError: Cannot read property 'getId' of undefined in React + truffle DApp

ethereum - 使用 Trezor(硬件钱包)将签名交易发送到 Ropsten 或 Truffle 开发网络

go - 如何在 Go SDK 中部署以太坊智能合约

go - Geth ecrecover 无效签名恢复id

javascript - 调用 web3.eth.personal.unlockAccount 会抛出错误

javascript - Web3/元掩码 : Error: Contract has not been deployed to detected network (network/artifact mismatch) on Kovan network