Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting to Ethereum node in web browser

Tags:

ethereum

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"));
like image 243
adrianmc Avatar asked Sep 27 '22 23:09

adrianmc


1 Answers

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

like image 103
Stas Natalenko Avatar answered Oct 30 '22 14:10

Stas Natalenko