CORS error in ethers.js

`Access to fetch at 'https://ropsten.infura.io/v3/124142142424XXX' from origin 'https://websitename.netlify.app' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.`

I don’t get it, sometimes it works, sometimes it doesn’t.

Here is the code that is intializing it

const privateKey = "XXX";
const INFURA_PROJECT_ID = "XXX",
      INFURA_PROJECT_SECRET = "XXX";

var provider = ethers.getDefaultProvider('ropsten', {
  infura: {
    projectId: INFURA_PROJECT_ID,
    projectSecret: INFURA_PROJECT_SECRET,
  }
});

var wallet = new ethers.Wallet(privateKey, provider);
var contract = new ethers.Contract(CONTRACT_ADDRESS, ABI, provider);
var contractWithSigner = contract.connect(wallet);

everything seems good and the code worked perfectly before infura came, I don’t know why its blocking resources from a website that is HTTPS

1 Like

I am using this guide to attaching Infura API

Hi @akc, and welcome to the Infura community!

Have you tried setting the requests’s mode to no-cors, or is that a possibility for you?

1 Like

Thank you for your reply, I looked into the headers and looks like it only happens when the website is using the browser cache instead of actually sending a request, so everything seems okay but I have one question very close to this one and that is, why my infura dashboard isn’t showing any activity? is it because I am using ropsten network for testing? is the dashboard there only for mainnet?

In my example, I have a smart contract loaded into the ropsten network through Ethereum Remix and it is working perfectly, I am sending information to it and eth is being deducted from my account like its supposed to, everything is great but just the dashboard from Infura isn’t showing any activity, please advise.

I’m getting the same error

I reall think its related to caching image

Hey @akc - with regard to the dashboard, it does take a little while to kick in, so if you’re not seeing activity a few hours after your requests were sent, please let us know and we’ll look into that. Are you seeing usage stats now?

And thanks for the caching idea! I’ve passed that along and we’re looking into it to figure out what our next steps are.

1 Like

Hey! the dashboard is working as expected now! but yes, it took time for the dashboard to update, I am assuming that the dashboard updates every 7 days, so all is fine.

Summary:
CORS error due to caching (nothing to worry about)
Dashboard updates every 7 days

1 Like