FR: facilitate debugging of "could not detect network (event="noNetwork", code=NETWORK_ERROR..."
See original GitHub issueErrors of the form Error: could not detect network (event="noNetwork", code=NETWORK_ERROR, version=providers/x.y.z)
seem to crop up quite a bit, e.g.:
https://github.com/ethers-io/ethers.js/issues?q=is%3Aissue+event%3D"noNetwork"++code%3DNETWORK_ERROR
There appears to be no indication in the error of what went wrong, or in the documentation about how to debug this. One cause appears to be non-functional RPC endpoints, but this is certainly not the only one. For example, I am seeing this from hre.ethers.provider
provided by hardhat-ethers
with an RPC endpoint URL which works perfectly fine via new ethers.providers.JsonRpcProvider(url)
.
So I would suggest any/all of the following, in order to facilitate root cause analysis:
- If possible, add more detail to the error message.
- If not, provide some kind of tracing of network activity (e.g.
export ETHERS_TRACE=network
or similar). - Add some suggested trouble-shooting procedures to the docs.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:8 (4 by maintainers)
Top Results From Across the Web
could not detect network (event="noNetwork", code - You.com
Here is my code being used for testing. It works in a small node program but will not work in React Native.
Read more >Error: could not detect network (event="noNetwork", code ...
This happens if you run the code in WSL but Ganache is opened in Windows. Follow along the URL given in another answer...
Read more >Error: Wallet has error: Error: could not detect network (event ...
Error: Wallet has error: Error: could not detect network (event="noNetwork", code=NETWORK_ERROR, version=providers/5.0.17).
Read more >Error: could not detect network - Moralis Forum
I am trying to connect to the speedy bsc mainnet node but i suddenly get the following error: Error: could not detect network...
Read more >Kony API Reference Guide | Manualzz
27.5 Registering for Network Status Change Notifications ... The API does not check for the availability of the media at the specified location....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The will help if the problem is the node is erroneously returning invalid responses. But for most other cases you won’t see much, unfortunately. 😦
This is usually a link error, which means there is not really any meaningful way to get more info. If it is more than a link error, the
provider.on("debug", console.log)
can probably help.Otherwise, link errors can occur because the node isn’t up and running yet, there is a firewall in the way (I.E mobile platforms like iOS and android block all http traffic), the geth instance hasn’t been configured to allow a connection over the default interface, etc.
There is not generally much that can be done at an application level to debug a bad network link as much of that is at the OS level, server configuration or network topology. 😒