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.

Allow JsonRpcProvider to retry getting its network after instantiation

See original GitHub issue

initializing jsonRpcProvider and calling any function before geth is healthy/run will return could not detect network (code=NETWORK_ERROR, version=providers/5.0.0-beta.164) this seems to work as expected

but once the geth is backed up, the error still persists.

I tried changing all the call to create a new instance of jsonRpcProvider and call the functions instead of initializing once as a singleton as example here

From

const ethers = require('ethers')
const { ETH_JSON_RPC_URL } = require('../../config')
const jsonRpcProvider = new ethers.providers.JsonRpcProvider({
  url: ETH_JSON_RPC_URL
})
module.exports = jsonRpcProvider

To

const ethers = require('ethers')
const { ETH_JSON_RPC_URL } = require('../../config')
const jsonRpcProvider = () => new ethers.providers.JsonRpcProvider({
  url: ETH_JSON_RPC_URL
})
module.exports = jsonRpcProvider

Now it works, once geth is up the server can connect to it without any problem.

also, if the jsonRpc is created after geth is healthy, but geth dies after the error is different

TypeError: Cannot read property 'body' of undefined
    at /home/jarindr/works/bitpend-backend/node_modules/@ethersproject/web/lib/index.js:138:41
    at step (/home/jarindr/works/bitpend-backend/node_modules/@ethersproject/web/lib/index.js:33:23)
    at Object.throw (/home/jarindr/works/bitpend-backend/node_modules/@ethersproject/web/lib/index.js:14:53)
    at rejected (/home/jarindr/works/bitpend-backend/node_modules/@ethersproject/web/lib/index.js:6:65)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

note: this also happen with v4 with different error like invalid response 0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
ricmoocommented, May 7, 2020

This should work now in 5.0.0-beta.185. The Provider API was tweaked a bit to better support network discovery in the event it fails when created.

1reaction
ricmoocommented, May 3, 2020

Yeah, I should trap the bad body results (it is returning XML, probably) and throw a server error instead.

If you connect a JsonRpcProvider to a node that is down, and do not provide a network, it will currently never work, but that is something I could easily change.

Until the feature is added, you can resolve this by passing in a network as the second parameter. But I’ll look into this today. I have a few other things I want to get to today too and this lines up well with them. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

jsonrpcprovider could not detect network - You.com - You.com
Go to the Ganache and click on Settings, then go the server and choose WSL as server. After this save and restart the...
Read more >
Provider in ethers_providers - Rust - Docs.rs
An abstract provider for interacting with the Ethereum JSON RPC API. Must be instantiated with a data transport which implements the `JsonRpcClient` trait ......
Read more >
Documentation - Ethers.js
A connection to the Ethereum network (a Provider); Holds your private key and can ... JsonRpcProvider(); // The provider also allows signing transactions...
Read more >
JsonRpcProvider - ethers
The JSON-RPC API is a popular method for interacting with Ethereum and is available in all major Ethereum node implementations (e.g. Geth and...
Read more >
ethers-io/Lobby - Gitter
do you know how remix and metamask give you the option to force it, ... to correctly instantiate an unlocked ganache account on...
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