question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

chrome 87.0.4280.66

I am use ethers.js 5.0.23 with infura eth api. I config ethers.js like (https://docs.ethers.io/v5/api-keys/):

const provider = ethers.getDefaultProvider(network, { infura: { projectId: “9d4f2ae6f5b44f0db52a9955432dfb21”, projectSecret: “secret”, } }); And I config infura ALLOWLIST ORIGINS:

https://mydomain.com

But, I get a error like blow: Access to fetch at ‘https://mainnet.infura.io/v3/api_key’ from origin ‘https://mydomain.com’ 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. Request URL: https://mainnet.infura.io/v3/api_key Referrer Policy: strict-origin-when-cross-origin Provisional headers are shown Authorization: Basic OmM5MmQ1ODU4NWI0YTRmOGNhOWZlNjUzZDg5ODBlMzIy content-type: application/json Referer: https://www.tokenswap.finance/ User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36 {method: "eth_call",…} id: 82 jsonrpc: "2.0" method: "eth_call" params: [{to: "0x19ab5001ca907dc0e2046c3675861e3e93461cef", data: "0x313ce567"}, "latest"]

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
aksdevaccommented, Dec 7, 2020

You should not use projectSecret if you are using it from browser, its big security risk. error also mention Authorization header issue, it won’t be allowed from browser by infura, please remove projectSecret.

0reactions
clowestabcommented, Jul 11, 2022

Stumbled upon this having had a similar issue connecting to an Infura node use a browserified instantiation of the ethers.js InfuraProvider. The idea that one can’t connect to an Infura node in the browser doesn’t seem right…

I’ve added it to my ‘to investigate’ list but given that an Etherscan provider works without issue I’m not all that bothered.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CORS errors - HTTP - MDN Web Docs - Mozilla
CORS errors. Cross-Origin Resource Sharing (CORS) is a standard that allows a server to relax the same-origin policy. This is used to ...
Read more >
3 Ways to Fix the CORS Error — and How the Access-Control ...
The error stems from a security mechanism that browsers implement called the same-origin policy. The same-origin policy fights one of the most ...
Read more >
CORS errors and how to solve them - Topcoder
CORS is an abbreviation for Cross-Origin Response Sharing. It is what allows the website on one URL to request data from a different...
Read more >
What Is a CORS Error and How to Fix It (3 Ways) - Bannerbear
As a CORS error occurs when the external API server doesn't return the HTTP headers required by the CORS standard, you can add...
Read more >
Understanding and Resolving CORS Error - Contentstack
CORS is implemented on the server-side; it cannot be reconfigured on the client-side. The CORS behavior, commonly termed as CORS error, is a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found