I know this question has been asked so many times. But I have not been able to solve my problem.

I am trying to connect to a remote node located on a server.

My server is running geth on rinkeby and RPC should be enabled thanks to this command:

admin.startRPC("", 8545, "*", "web3,db,net,eth")

In my code (NodeJS), I have the following:

function getNode(callback) {
    var web3;
    web3 = new Web3(new Web3.providers.HttpProvider("https://X.X.X.X:8545"));
    if (web3 != null) {
        console.log("GOT WEB3");
        callback(null, web3);
    } else {
        console.log("did not get web3");
        callback("ERROR", web3);

The web3 variable is undefined at the first log, and is returning an object after I get the HTTP provider.

However, I have this error in my console:

Error: Invalid JSON RPC response: "" at Object.InvalidResponse (D:\node_modules\web3\lib\web3\errors.js:38:16) at XMLHttpRequest.request.onreadystatechange (D:\node_modules\web3\lib\web3\httpprovider.js:119:24)

What I have done wrong?

Edit: TCP and UDP are all openned on port 8545.


Current command to launch geth:

geth --rinkeby console -rpc -rpcaddr "" --rpccorsdomain "*"

Current NodeJS code:

function getNode(callback) {
    var web3 = new Web3();
    web3.setProvider(new web3.providers.HttpProvider("https://server_external_ip:8545/"), function(error, result) {
        if (error) {
            callback("ERROR", web3);
        } else {
            callback(null, web3);

This is what netstat gives me:

tcp6       0      0 :::8545                 :::*                    LISTEN      3565/geth 

Result: serverless gives me a timeout. If no timeout indicated, it runs infinitely without getting anything.

  • which version of Web3 do you require in your code?
    – SCBuergel
    Dec 4, 2017 at 10:21
  • I require 1.0.0 beta.26 @ValidityLabs-Sebastian Dec 4, 2017 at 10:23

1 Answer 1


You need to make geth listen on the IP address from which your server can be reached externally:

admin.startRPC(<external ip address>, 8545, "*", "web3,db,net,eth")

If you specify the localhost, geth accepts only local connections, i. e. connections that come from the same machine, but not from remote.

  • Makes sense. But it returns this Error: listen tcp MY.IP.IS.HERE:8545: bind: cannot assign requested address Dec 5, 2017 at 0:32
  • Sounds like the port is already used by some server. Have you checked, e.g with lsof -i TCP| fgrep LISTEN (on Linux)?
    – gisdev_p
    Dec 5, 2017 at 0:38
  • It only gives the following: geth 2809 myname 33u IPv6 47912 0t0 TCP *:30303 (LISTEN) Same error for random ports Dec 5, 2017 at 0:44
  • Just checked the error message. It's not about the port but the address. Are you sure about the IP address? If you are using a VM in the cloud, the VM usually has an internal and an external IP address
    – gisdev_p
    Dec 5, 2017 at 0:56
  • I tried with the external address and internal one. Only the internal one worked. But when I try to send a request, I still have the same error as described in the question Dec 5, 2017 at 0:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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