TransWikia.com

CORs Error for /v1/chain/push_transactions To Production Block Producer (Not localhost)

EOS.IO Asked by rsmets on November 10, 2021

All of my other POST calls to a production EOS BP are succeeding no problem. However, when I use push_transactions via ScatterJS I get a 500 CORs error.

const networkJson = {
  blockchain:'eos',
  host:'api1.eosasia.one',
  port:443,
  protocol:'https',
  chainId:'aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906'
};

const network = ScatterJS.Network.fromJson(networkJson);
const rpc = new eosjs2.Rpc.JsonRpc("https://api1.eosasia.one:443", { fetch });
const api = ScatterJS.eos(network, Api, {rpc})

async function takeScatterAction(action, dataValue, account) {
  const id = await ScatterJS.login();
    if (!id) {
      alert(`not logged in`)
    }

  // error is in while executing this api.transact call. 
  const resultWithConfig = await api.transact(
    {
      actions: [
        {
          account: CONTRACT_NAME,
          name: action,
          authorization: [
            {
              actor: account.name,
              permission: account.authority
            }
          ],
          data: dataValue
        }
      ]
    }
    ,
    {
      blocksBehind: 3,
      expireSeconds: 30
    }
  );
  console.log(resultWithConfig);
  debugger;
  return resultWithConfig;
}

By calls to get chain info succeed no problem: /get_block, /get_required_keys, get_info, get_table_rows.

Curious what I may be doing incorrectly? Thanks for your input!

One Answer

Ahh I was able to sort things out. TLDR: swapping the nodeos API endpoint from https://api1.eosasia.one:443 to https://eos.greymass.com did the trick.

The CORs error was a little odd. It comes from the server configuration. Many of the other posts I read in regard to a similar error were in reference to the localhost nodeos setup. The solution for that scenario is to Allow Origin: *, meaning allow requests from any hosts. But given I have no control over the eosasia server configuration I was little stumped. I thought maybe I had to apply to be an "officially recognized dapp" so that they would honor requests from my domain, eosacl.herokuapp.com.

However upon exploring and interacting with my smart contract via EosAuthority, https://eosauthority.com/account/myeosacldapp?network=eos&scope=myeosacldapp&table=locks&limit=10&mode=contract&sub=actions&lower_bound=&action=revokekey, I noticed they were using https://eos.greymass.com for there nodeos API endpoint. Upon giving that a shot everything worked great!

I originally landed on https://api1.eosasia.one:443 because that was the first URL I could get to return mainnet account info via cleos. I become aware of that api endpoint via eosnation's tool, https://validate.eosnation.io/eos/producers//?api_endpoint=y, in case anyone is interested. Odd that Greymass is not on there? I guess they are not a block producer?

I hope this helps someone who runs into something similar down the line.

Answered by rsmets on November 10, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP