Connecting to Ethereum node in web browser

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-05 02:40:58

问题


I'm getting this error:

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

I'm currently trying to use a Meteor app with a node on a private test network. I've also tried running it on a real node on the real network as well. I am able to access the web3.eth objects, but I can't seem to connect to my node! It's so frustrating!

My app runs on http://localhost:3000

I've tried the following in launching my nodes, neither of them work (they launch okay, but I cannot connect to them through my browser):

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

This is what I use to set the provider in the browser console:

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

回答1:


I think I was getting the same error, when was trying to run geth in a VM. And in that case the issue was with RPC listening to localhost only. Binding it to all addresses with --rpcaddr "0.0.0.0" solved the problem:

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

Important thing to note here is that with a such configuration the port will be open to connections from the outside world, if it's not on a private network or not protected with a firewall.

You can also check if the RPC port is open by trying to connect to it with telnet:

telnet localhost 8545



来源:https://stackoverflow.com/questions/32111063/connecting-to-ethereum-node-in-web-browser

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!