I'm trying to simply connect to my local EOS block from within a React Component with the following code;

import EOSJS from 'eosjs';

const config = {
    keyProvider: ['INSERT_PRIVATE_KEY_HERE'],
    httpEndpoint: '',
    expireInSeconds: 60,
    broadcast: true,
    debug: false,
    sign: true

const eos = EOSJS.Localnet(config);

eos.getInfo({}, function(err, result) {
    err ? console.log("Error:",err) : console.log("Response:",result);

and receiving the following error;

Failed to load No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

My local EOS blockchain instance is configured as such;

http-server-address =
access-control-allow-credentials = false
unlock-timeout = 7400000 #900
producer-name = eosio
enable-stale-production = true

plugin = eosio::http_plugin
plugin = eosio::chain_api_plugin
plugin = eosio::history_api_plugin
plugin = eosio::wallet_api_plugin
plugin = eosio::producer_plugin

Executing curl returns the correct block state and running the exact same javascript code server side through nodejs also works. I'm guessing I need to somehow modify the eosjs library to exclude CORS from http requests, or allow it somehow in my config.ini, but I'm not sure how to.


Just add the below param to your config file:

access-control-allow-origin = "*"

Or you can even run the nodeos command with this parameter, check mine:

nodeos -e -p eosio --plugin eosio::chain_api_plugin --plugin eosio::history_api_plugin --access-control-allow-origin "*" --access-control-allow-headers "*" --access-control-allow-credentials true

Maybe trivial, but try to change the config to localhost instead of

  const config = {
    httpEndpoint: 'http://localhost:8888',
  • Great idea! Leo solved it with configuration variables above. But checking my hosts file is configured correctly would be good practice. – Mitch Pierias May 27 '18 at 7:01

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.