2

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.

3

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
|improve this answer|||||
  • hi thomas thanks for suggestion ,tried by changing the port make it same in my web3 and in geth command but still getting same error...!! what else i need to do ? – user1996411 Aug 15 '17 at 6:50
  • One question ..in web3 set providers what i need to put ip of the node,domain,localhost or 0.0.0.0 ? – user1996411 Aug 15 '17 at 6:59
  • The IP that the node is running on, or a domain pointing to that IP. – Thomas Clowes Aug 15 '17 at 11:14
0

I had the same trouble and spend a lot of time to find the reason. web3.js has XMLHttpRequest (npm module) as a dependency. This module writes some temp files when sending a request. (see here: xmlhttprequest source, line 477 )

It means your NodeJs process needs to write files permission

|improve this answer|||||
0

I think its a CORS issues. I tried to Turn off CORS. For example:

1.how to turn off cors in chrome

  1. Use a plugin for your browser
  2. Use a proxy such as nginx. example of how to set up

It actually worked. For development is fine

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.