I run:

geth --rinkeby --rpc --rpcport=8545 --rpcaddr= 

It works in console:

 geth attach

> eth.syncing
> eth.accounts

Truffle migrate also works with

module.exports = {
  networks: {
    "geth": {
      network_id: "*",
      host: "",
      port: 8545

But when I run:

Web3 = require('web3')
web3 = new Web3(new Web3.providers.HttpProvider(""));

web3.eth.getAccounts().then(e => console.log(e));

I takes a couple of minutes and I get:

Error: Invalid JSON RPC response: ""

When I use --rpcaddress=localhost it works but of course only from localhost

I doesn't matter what version I use. Currently using:

geth: 1.9.6-stable

web3: 1.2.1

Truffle v5.0.38

Any ideas? Please!


3 Answers 3


I don't know the infrastructure of your current project.

However it is worth to try changing:

web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));


web3 = new Web3(new Web3.providers.HttpProvider(""));

You are using geth attach with this IP as well so it might solve your problem.

Edit 1: As it seems to be a problem with the networking here is what you need to do:

Most likely your rpcaddr is This means only the server/local machine can access this node/blockchain.

So you need to make a change in order to allow external connections.

The easy way to do this is with rpcaddr But this is very insecure. Now everyone can access your node. So you should specify which IP can access your node.

Either manually input your device IP which wants access or build an API around it which handles this stuff for you.

Here is the easy way which allows connections from all devices:

Start geth with these two properties specified as well:

--rpcaddr and --rpccorsdomain "*"

Keep in mind there are various solutions and the one I pointed out works in all cases but isn't secure. As mentioned you should specify the IP of the server/client which is supposed to connect to the blockchain.

EDIT 2: Now your command should look like this:

geth --rinkeby --rpc --rpcport=8545 --rpcaddr --rpccorsdomain "*"

  • 1
    This partially helps. The issue seems to be calling it from other hosts on the network. If I use --rpcaddr=localhost everything works FROM localhost but from other hosts If I use --rpcaddr=, the hosts IP, geth works but not web3. Not even from localhost. Oct 17, 2019 at 14:56
  • 1
    I updated my answer to solve your problem.
    – cqx
    Oct 17, 2019 at 15:44
  • 1
    Still fails. The odd thing is that it works for both truffle and geth attach from the other hosts. However, using the same settings Web3(new Web3.providers.HttpProvider("")) fails. it only works for localhost. Also, if I use a fake IP address in web3 I get the same behavior! Oct 17, 2019 at 18:10
  • 1
    You have a typo in the code you just sent (the ip). I assume that your you didn't do that in your code. However please see my edit and make sure that you include the rpcaddr with "". Maybe the firewall blocks the connection?
    – cqx
    Oct 17, 2019 at 18:29
  • Still fails, It seems it is a security issue with invoking it with web3js. I'm posting my workarond now. THANKS! Oct 17, 2019 at 20:56

It seems to be an issue with invoking with web3 via a nonsecure http connection, although I don't know why. This is what I did to get it to work:

Set up an ngrok secure tunnel

Run geth as follows:

geth --rinkeby --rpc --rpcport=8545 --rpcaddr --rpccorsdomain "*"

Use the following URL to connect from anywhere. It works with truffle, geth console, and web3js.


This is probably the safe solution anyway but it would be nice to be able to develop without it.


If you are like me and a noob in docker or docker-compose don't refer to other containers with localhost. Use the container name instead. So if your docker compose file is:

version: '3'
    image: trufflesuite/ganache-cli
    container_name: ganache-dev
      - ./ganache:/home/ganache
      - "8545"
      - .env
      - "8545:8545"

connect to http://ganache:8545. Hope this helps someone.

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.