I am running a full rinkeby node via

geth --rinkeby --rpc --rpcapi db,eth,net,web3,personal --cache=2048  --unlock="..." --password ... --rpccorsdomain "*" --allow-insecure-unlock --rpcaddr "localhost"

The node is up and I could deploy a smart contract via truffle migrate --rinkeby and the config

rinkeby: {
      host: "localhost", // Connect to geth on the specified
      port: 8545,
      from: "...", // default address to use for any transaction Truffle makes during migrations
      network_id: 4,
      gas: 4612388 // Gas limit used for deploys

My DApp is supposed to connect to the blockchain:

var web3Provider = new Web3.providers.HttpProvider('http://localhost:8545');
var web3 = new Web3(web3Provider);
var startBlock = web3.eth.blockNumber;

I get the following error (Firefox, similar for Chromium):

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8545/. (Reason: CORS request did not succeed)
Error: CONNECTION ERROR: Couldn't connect to node http://localhost:8545.

My DApp runs on an nginx webserver (nginx/1.14.0 (Ubuntu)).

My geth version is 1.8.27.

Any ideas on what else I could try?

  • try to start geth with --rpcaddr and in the config file use host: "". if the problem persists what about – Badr Bellaj Jun 6 '19 at 11:55

In your case CORS configuration should be set on the Geth node and not on the nginx server that serves your DApp.

You can play on the --rpccorsdomain configuration flag when starting your Geth node.

e.g geth [OPTS...] --rpccorsdomain "<dapp-domain>"

where <dapp-domain> is the domain your dapp is exposed on by nginx.

| improve this answer | |
  • I played with different options for rpccorsdomain. In particular, I tried --rpccorsdomain "*", which should be the most open. Still, I get the same error. – mcb Jun 9 '19 at 18:22

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.