Error: Wallet has error: Error: could not detect network (event=“noNetwork”, code=NETWORK_ERROR, version=providers/5.0.17)
See original GitHub issueAfter enabling JWT token authentication on besu network, a connectionInfo with JWT token in headers is used to make connection to the network, instead of url.
import { ContractFactory, ethers } from "ethers";
let connectionInfo = { //<<==connectionInfo may have problem. Used to use url and worked fine.
url: GLOBAL.PROVIDER_URL, //<<=="http://my-ip:80"
headers: {
"Bearer": tokenBesu //<<==tokenBesu is validated on jwt.io and OKed with cUrl command querying the network
},
};
const provider = new ethers.providers.JsonRpcProvider(connectionInfo); //<<==used to be url
wallet = new ethers.Wallet(privateKeyBesu, provider); //<<== this line throws error
Also tried:
const provider = new ethers.providers.JsonRpcProvider(connectionInfo, 2018); //<<==2018 is chain id
The error is the same with wallet.
However querying network with cUrl (provided by Besu doc) in command line returns true.
$ curl -X POST -H 'Authorization: Bearer tokenBesu' -d '{"jsonrpc":"2.0","method":"net_listening","params":[],"id":1}' http://my-ip:80
{
"jsonrpc" : "2.0",
"id" : 1,
"result" : true
}
The network is running fine. The app calling JsonRpcProvider has React Native 0.62.3.
Here are returns of eth_chainId and eth_netowrkId in command line with curl:
$ curl -X POST -H 'Authorization: Bearer tokenBesu' -d '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":1}' http://my-ip:80
{
"jsonrpc" : "2.0",
"id" : 1,
"result" : "0x7e2" //<<==2018 which is the network id
}
$ curl -X POST -H 'Authorization: Bearer tokenBesu' -d '{"jsonrpc":"2.0","method":"eth_networkId","params":[],"id":1}' http://my- ip:80
{
"jsonrpc" : "2.0",
"id" : 1,
"error" : {
"code" : -32601,
"message" : "Method not found" //<<==not sure why eth_networkId was not found.
}
}
Before enabling JWT token authentication, the Besu was running fine with contract deployment, contract method calling and so on.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7
Top Results From Across the Web
Error: could not detect network (event="noNetwork", code ...
So, Ganache is not connected to different environment. Go to the Ganache and click on Settings, then go the server and choose WSL...
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 >Getting Error: could not detect network (event="noNetwork ...
Is Mumbai selected in your wallet? Try using another RPC URL in your wallet. E.g. https://matic-mumbai.chainstacklabs.com or ...
Read more >error: could not detect network (event="nonetwork ... - You.com
Error: Wallet has error: Error: could not detect network (event=“noNetwork”, code=NETWORK_ERROR, version=providers/5.0.17) #1430.
Read more >Pokt RPC url on Mumbai has issues with getBalance call
Error : could not detect network (event="noNetwork", code=NETWORK_ERROR, version=providers/5.5.2). If I change the RPC url to one of the ...
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 Free
Top 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

The JsonRpcProvider makes
eth_chainIdcalls before every request to ensure proper chain id (even though you have already provided chain id when creating the provider). When this call fails for some reason, you get this errorcould not detect network.For constant chain id providers, you can use
StaticJsonRpcProvider, this assumes the chain id that doesn’t change.I had a quick look in the docs and seems it’s not there. Will be added soon! For now it’s API is pretty much same as JsonRpcProvider.