在Web浏览器中连接到以太坊节点

时间:2015-08-20 06:33:26

标签: ethereum

我收到此错误:

CONNECTION ERROR: Couldn't connect to node http://localhost:8545, is it running?

我目前正在尝试将Meteor应用与私有测试网络上的节点配合使用。我也试过在真实网络上的真实节点上运行它。我能够访问web3.eth对象,但我似乎无法连接到我的节点!这太令人沮丧了!

我的应用程序在http://localhost:3000

上运行

我在启动节点时尝试了以下操作,它们都不起作用(它们启动正常,但我无法通过浏览器连接到它们):

geth --networkid 8545 --genesis ~/genesis_block.json --datadir ~/.ethereum_experiment console
geth --rpccorsdomain "*" --rpc --networkid 8545 --minerthreads "1" --datadir ~/.ethereum_experiment --mine

这是我用来在浏览器控制台中设置提供程序的内容:

web3.setProvider(new web3.providers.HttpProvider("http://localhost:8545"));

1 个答案:

答案 0 :(得分:3)

我想在尝试在VM中运行geth时遇到了同样的错误。在这种情况下,问题是RPC只监听localhost。使用--rpcaddr“0.0.0.0”将其绑定到所有地址解决了问题:

geth --rpc --rpcaddr "0.0.0.0" --rpcport 8545 --nodiscover --networkid "$NETWORKID" --datadir ~/.ethereum_experiment --genesis ~/genesis_block.json

这里需要注意的重要一点是,如果没有这样的配置,端口将对来自外部世界的连接开放,如果它不在专用网络上或没有防火墙保护。

您还可以通过尝试使用telnet连接到它来检查RPC端口是否已打开:

telnet localhost 8545