FallbackProvider not catch detectNetwork error
See original GitHub issueEthers Version
5.6.0
Search Terms
No response
Describe the Problem
the issue is regarding the fallback-provider. i have 3 providers configured and the quorum is set to 1. However, the query request (such as getBalance) will fail with only 1 JsonRpcProvider malfunction. As the quorum is set to 1, that’s not expected to happen.
After digging into the source code, i find the detectNetwork
function is not catching the no network error.
i have made changes to the original source code, and then my test passed.
below is the new code
async detectNetwork(): Promise<Network> {
const networks = await Promise.all(
this.providerConfigs.map(async (c) => {
try {
return c.provider.getNetwork();
} catch (error) {
return null;
}
}),
);
return checkNetworks(networks as Array<Network>);
}
also in checkNetworks
, the check should continue in the for loop when no network is provided
if (network == null) {
continue;
}
Code Snippet
the way i initiated a FallbackProvider
new FallbackProvider(
[
{
provider: new ethers.providers.JsonRpcProvider(url1),
priority: 3,
stallTimeout: 200,
weight: 1,
},
{
provider: new ethers.providers.JsonRpcProvider(url2),
priority: 1,
stallTimeout: 200,
weight: 1,
},
{
provider: new ethers.providers.JsonRpcProvider(url3),
priority: 2,
stallTimeout: 200,
weight: 1,
},
],
1,
);
Contract ABI
No response
Errors
No response
Environment
node.js (v12 or newer)
Environment (Other)
No response
Issue Analytics
- State:
- Created a year ago
- Reactions:3
- Comments:6 (1 by maintainers)
Top Results From Across the Web
ZuulFallbackProvider not getting invoked - Stack Overflow
No specific error message from Zuul. The request just fails with 500 error, which would be the expected behavior if the fallback was...
Read more >Transaction Details - Galileo POA Explorer
... new Error("empty");return!0}catch(e){}return!1}function d(t){"string"! ... detectNetwork()),e||F.throwError("no network detected" ...
Read more >dist/ethers.esm.js - Renovate Bot Package Diff
+ catch (error) { ... The Cloudflare provider does not support eth_blockNumber, ... caught up to the FallbackProvider, before sending a request to...
Read more >Providers - Ethers.js
It creates a FallbackProvider connected to as many backend services as possible. ... If no network is provided, homestead (i.e. mainnet) is used....
Read more >Providers — ethers.js 4.0.0 documentation
If you are not running your own local Ethereum node, it is recommended that you ... This creates a FallbackProvider backed by multiple...
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
@cliff0412 A PR would be super helpful IMO. I wouldn’t ask permission, but rather just contribute the PR and let the maintainers decide whether it’s worth including.
Do you have a link to your fork so I may evaluate your code-changes and fork from your fixed state until the change moves upstream?
@ricmoo i have forked and made a pr. pls refer to https://github.com/ethers-io/ethers.js/pull/3247