question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: Wallet has error: Error: could not detect network (event=“noNetwork”, code=NETWORK_ERROR, version=providers/5.0.17)

See original GitHub issue

After 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:closed
  • Created 2 years ago
  • Comments:7

github_iconTop GitHub Comments

5reactions
zemsecommented, Apr 9, 2021

The JsonRpcProvider makes eth_chainId calls 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 error could not detect network.

For constant chain id providers, you can use StaticJsonRpcProvider, this assumes the chain id that doesn’t change.

1reaction
zemsecommented, Apr 9, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found