CORS Error
See original GitHub issuechrome 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:
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:
- Created 3 years ago
- Comments:5 (1 by maintainers)
Top GitHub Comments
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.
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.