5

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"));
adrianmcli
  • 1,956
  • 3
  • 21
  • 49

2 Answers2

4

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

  • I later on found out that it had to do with the fact that I required the RPC port setting. I originally thought networkid was what determined the port, but it's something else entirely. – adrianmcli Aug 22 '15 at 11:29
  • 1
    Or you can test with geth "geth attach rpc:http : //192.168.100.2:7001" – Max Feb 19 '16 at 23:07
  • @Max how do you run geth attach if a geth rpc node is running simultaneously? Or does the node not have to be running for that to work? – babycakes May 18 '16 at 04:38
  • Is this still a working answer for you? I am using: geth --testnet --rpccorsdomain "*" --rpc --rpcaddr "0.0.0.0" – babycakes May 18 '16 at 04:43
  • I can connect via telnet, but the meteor app continues to say that the connection fails... – fccoelho Jul 25 '17 at 14:48
  • I have the same problem as @fccoelho. I can connect via telnet but the Remix doesn't connect to the Web3 Provider of my Virtual Machine – Urko Jan 03 '18 at 14:59
-2

A simple solution is to use a node provider like Alchemy or Infura!

https://docs.alchemy.com/alchemy/introduction/getting-started

  1. Make an Alchemy key by signing up for an account and creating an app

  2. Replace your web3 setup with something like this:

const { createAlchemyWeb3 } = require("@alch/alchemy-web3"); // Using HTTPS const web3 = createAlchemyWeb3("https://eth-mainnet.alchemyapi.io/<api-key>");

You can use free nodes from one of these node providers and avoid the hassle of maintaining your nodes yourself.