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.

JsonRpcProvider giving UnhandledPromiseRejectionWarning when detectNetwork rejects

See original GitHub issue

Sorry if I’m interrupting too much. Running into issues 😦

I am in a situation where ganache takes a while to start while my node js script loads up quickly. I am passing url into JsonRpcProvider constructor. But this throws up UnhandledPromiseRejectionWarning that I am not able to silence. It’s breaking my pre-commit hook.

I digged in to the ethers.js code base and found that the networkOrReady promise is getting rejected in my case and there is no way to silence the warning.

https://github.com/ethers-io/ethers.js/blob/d817416bae2fbc7adb8391fd038613241b7ab8ba/packages/providers/src.ts/json-rpc-provider.ts#L233-L241

You can reproduce this with:

const ethers = require('ethers');

(async () => {
  try {
    const provider = new ethers.providers.JsonRpcProvider(
      'http://localhost:7545'
    );
  } catch (error) {
    console.log('Error is silenced');
  }
})();

Analyzing if this is a bug or not, if we take a web app example where user inputs a URL of node which can be valid or might not be. The developer should be able to catch the error without having it leak into the browser console.

Also, I started getting this when I updated from beta.189 to 5.0.1 (@ethersproject/providers moved from 5.0.0-beta.169 to 5.0.1).

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
ricmoocommented, Jun 14, 2020

Oh, also keep in mind the constructor won’t throw if the network cannot be detected, since that can only be discovered asynchronously.

I think it makes sense to make the provider.ready promise stall (with exponential backoff) until the network has been successfully detected though.

So, after this change you’ll be able to do:

(() => {
  const provider = new JsonRpcProvider();
  await provider.ready;

  // Now the provider is ready to go and you can call it normally
})();
1reaction
ricmoocommented, Jun 14, 2020

Can you try out 5.0.2 and let me know if that solves your issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ethers.js JsonRpcProvider Geth node in a Docker environment
I am trying to connect Ethers.js to a local Ehereum node (Geth) running in a Docker container. On the client side, I'm creating...
Read more >
ethers-io - Bountysource
I created a test account on Ropsten and gave myself 2 ETH. And now i'm trying to find the best way to swap...
Read more >
jsonrpcprovider could not detect network - You.com - You.com
I am trying to connect Ethers.js to a local Ehereum node (Geth) running in a Docker container. On the client side, I'm creating...
Read more >
How to Build a Full Stack NFT Marketplace - V2 (2022)
JsonRpcProvider. .next\static\chunks\pages\index.js (334:0) Generator.throw rejected /_next/static ...
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 >

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