ethers.js: could not detect network (event="noNetwork", code=NETWORK_ERROR, version=providers/5.0.5) in React Native Expo
Here is my code being used for testing. It works in a small node program but will not work in React Native.
import "@ethersproject/shims";
import { ethers } from "ethers";
const NodeAddress = "http://34.87.222.10:8545";
// ....
useEffect(() => {
(async () => {
try {
let p = await ethers.providers.getDefaultProvider(NodeAddress);
await p._networkPromise;
console.log(p);
} catch (e) {
console.log(e);
}
})();
}, []);
// ....
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 22 (7 by maintainers)
Strangely,react native does not work with the current version of ethers library but it works fine with ethers version 5.0.5 and lower
I think there may be. Depending on your setup (again, if you are using a proxy, things might further be affected), but you might want to adjust the network device to be any (I think you do this by specifying
0.0.0.0
) and you might need to add the CORS origin flag to allow any (I don’t know the key or value to set for this).If it is using CORS, make sure your Proxy is set up to forward
OPTIONS
too.Setting up a link is definitely non-trivial…
@ricmoo Thanks for the assistance. The issue is the non-https blocking like you mentioned.
You don’t need to await on
getDefaultProvider
, and can you try usingawait provider.ready
instead and see if that helps?Is the NodeAddress reachable from the phone/computer you are using? Keep in mind that iOS blocks non-https (i.e. http) traffic for example. Android may do something similar…
You can try hitting the host directly to test the link.