0

I have a problem with trongrid. I dont know what to do. On trongrid i create API and put it in index.js What config should i have on api settings on trongrid?

Console

enter image description here

Access to XMLHttpRequest at 'https://api.shasta.trongrid.io/wallet/getnodeinfo' from origin 'http://localhost:3000' has been blocked by CORS policy: Request header field tron-pro-api-key is not allowed by Access-Control-Allow-Headers in preflight response.

Here is my index.js

const TRONGRID_SHASTA_API = 'https://api.shasta.trongrid.io';

const HttpProvider = TronWeb.providers.HttpProvider;
const fullNode = new HttpProvider(TRONGRID_SHASTA_API);
const solidityNode = new HttpProvider(TRONGRID_SHASTA_API);
const eventServer = new HttpProvider(TRONGRID_SHASTA_API);
const privateKey = "c4f27f7b0523507**********************ecddfb21c891";
const tronWeb = new TronWeb(fullNode, solidityNode, eventServer, privateKey);
tronWeb.setHeader({'Content-Type': 'application/json',
    'Access-Control-Allow-Headers': '*',
    'Access-Control-Allow-Origin': '*',
    'TRON-PRO-API-KEY': '6ad9cb75-****-4f4c-a9cf-2156aa5e8453'});



async function triggercontract(){
    console.log("trx:", tronWeb.trx);
    console.log(tronWeb.transactionBuilder);
    console.log(tronWeb.utils);
    let instance = await tronWeb.contract().at("TNS*******tST9zAqXXssho5hgZ");
    let res = await instance.f().call();
    let res1 = await instance.g().call();
    console.log("res", res);
    console.log("res1", res1);
}

UPD 1: I understand that: I have simple react-app, when i start it it up on localhost:3000 and it makes requests to api.shasta.trongrid.io/..... making post requests but api.shasta.trongrid.io dont give access to this localhost cause i dont have cors but how to set it cors correctly to work it project? UPD 2: enter image description here Why my browser simply get info from this link, but react-app not? What should i do?

Denis Deniben
  • 93
  • 2
  • 10
  • I believe the issue lies with the local server running your react app. It refuses to get info from any remote server. Something along these lines may help. https://www.telerik.com/blogs/dealing-with-cors-in-create-react-app Best of luck – not-bob Mar 25 '21 at 01:14
  • @not-bob i added " "proxy": "http://localhost:4000"" to package.json but nothing happens, problem the same... – Denis Deniben Mar 25 '21 at 07:29
  • Here is a similar question on StackOverflow that may be useful. https://stackoverflow.com/questions/46337471/how-to-allow-cors-in-react-js – not-bob Mar 26 '21 at 17:32

0 Answers0