ethers-io / ethers.js

Complete Ethereum library and wallet implementation in JavaScript.
https://ethers.org/
MIT License
7.91k stars 1.84k forks source link

Ronin JSONRPC CORS error when looking into events but working fine for other things #2810

Open Maurechi opened 2 years ago

Maurechi commented 2 years ago

Discussed in https://github.com/ethers-io/ethers.js/discussions/2807

Originally posted by **Maurechi** March 15, 2022 Hey, so I'm trying to interact with Axie Infinity's Lands contract on Ronin Mainnet. I can call `contract.name()` and get the name. `contract.balanceOf(wallet)` also works fine. The issue comes when I want to look into the transfer events, or any event at all. Summarized Error here : ``` Access to fetch at 'https://api.roninchain.com/rpc' from origin 'http://localhost:3000' has been blocked by CORS policy: 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. geturl.js?0d04:30 POST https://api.roninchain.com/rpc net::ERR_FAILED 403 index.js?ffb2:185 Uncaught (in promise) Error: missing response (requestBody="{\"method\":\"eth_getLogs\",\"params\":[{\"fromBlock\":\"0x0\",\"toBlock\":\"latest\",\"address\":\"0x8c811e3c958e190f5ec15fb376533a3398620500\",\"topics\":[\"0x7e644d79422f17c01e4894b5f4f588d331ebfa28653d42ae832dc59e38c9798f\"]}],\"id\":45,\"jsonrpc\":\"2.0\"}", requestMethod="POST", serverError={}, url="https://api.roninchain.com/rpc", code=SERVER_ERROR, version=web/5.5.1) at Logger.makeError (index.js?ffb2:185:1) at Logger.throwError (index.js?ffb2:194:1) at eval (index.js?37b9:205:1) at Generator.throw () at rejected (index.js?37b9:6:42) ``` I see that it looks like a CORS issue but I'm not sure why would my previous requests work fine. I'm guessing since we are accessing their own evm maybe things are different? I'm not sure if I would need an APIKey (which I haven't seen the axie team posting about anywhere) or if there's anyway to change the `JsonRpcProvider` to change its CORS. My Code Below Also if anybody wants to try the rpcUrl is : `'https://api.roninchain.com/rpc'` and contractAddress is `8c811e3c958e190f5ec15fb376533a3398620500` `// It shows up like this, but works without the 'ronin:' ronin:8c811e3c958e190f5ec15fb376533a3398620500` They do have their own methods, but any ERC-721 ABI should work for this example ``` const finalProvider = new ethers.providers.JsonRpcProvider( Chains.RONIN_MAINNET.rpcUrl ) const axieContract = createAxieLandContract(finalProvider, contractAddress) const owner = await axieContract.ownerOf( BigNumber.from( '115792089237316195423570985008687907814818077203574517667432170581469777887231' ) ) const balance = (await axieContract.balanceOf(address)).toString() console.log({ balance }) console.log({ address }) console.log({ owner }) const ev = axieContract.filters.Transfer(undefined,address) const axieTransfer = (await axieContract.queryFilter(ev)) as | never[] | TransferEvent[] console.log({axieTransfer}) ``` ![Screen Shot 2022-03-15 at 11 25 02](https://user-images.githubusercontent.com/71376233/158357677-651045ba-9aab-4b2b-8fc2-2dfaf3d560f0.png)
specialOne-coder commented 2 years ago

Same issue with https://rinkeby-light.eth.linkpool.io , have you found the answer please ?

Maurechi commented 2 years ago

no.. I had to use an API from Axie-Infinity. But would still be nice to just query the chain