[Ethereum] Error: CONNECTION ERROR: Couldn’t connect to node

dapp-developmentweb3js

I am trying to access my Geth node (specifically a smart contract at a particular address) running on a remote server from my UI (Angular JS)

It works perfectly when using localhost or the ipv4 address on the same machine.

When trying to run the same code using the public IP address (ports are open), I am getting an error:

Error: CONNECTION ERROR: Couldn't connect to node http://xxx.xxx.xxx.xx:8585.

My code is as follow:

var Web3 = require('web3'); var web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider('http://x.x.x.x:8888'));

I have tried the following:

1) tried with local host or ipv4 at x.x.x.x
2) tried with 0.0.0.0 at x.x.x.x
3) public ip at x.x.x.x

My Geth command is:

geth  --rpccorsdomain "*" --rpc --rpcport "8585" --rpcaddr 0.0.0.0 --datadir="myChain" --port "30302"  --autodag --networkid 65535 --nat=none -
-rpcapi="db,eth,net,web3,personal,web3"  --nodiscover -verbosity 5 --maxpeers 3
console

Any suggestions?
Thanks in advance.

Best Answer

You have opened up your node on port 8585 yet are attempting to connect on port 8888.

Your code should be:

var Web3 = require('web3'); 
var web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider('http://x.x.x.x:8585'));

Also, you are running your node with loads of parameters. Do you know what they all do?

I would suggest reading the docs.

geth --fast --rpc --rpccorsdomain="https://TheDomainYouAreAccessingTheNodeFrom.com" --rpcaddr=TheIPOfTheNode --rpcapi eth,web3
Related Topic