-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Workaround for ethers.js bug in webpack environments #538
Conversation
Workaround from ethers-io/ethers.js#3536 (comment) Signed-off-by: Josh Chang <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for digging into this!
Could you change the JsonRpcProvider
to StaticJsonRpcProvider
?
We have just got this PR up (#537) which could half to RPC request time by simply changing it to static
Sure let me try |
@Ansonhkg Okay I changed it to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default, when you create a new provider, ethers.js performs an initial setup that involves fetching network information (such as the network name and chain ID). This setup ensures that the provider is correctly configured to interact with the specified network.
The skipFetchSetup
option allows you to skip this initial network information fetch. This can be useful in scenarios where you want to delay the network setup or when you already have the necessary network information and want to avoid the additional request.
This LGTM. @MaximusHaximus WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much for the contribution @joshdchang :D We really appreciate it.
FYI, this change is a little bit different than you described @Ansonhkg -- this is literally controlling how fetch()
is called rather than controlling whether chainId
is checked (which was the difference between JSONRPCProvider
and StaticJSONRPCProvider
)
From the docs:
connection.skipFetchSetup ⇒ boolean
Normally a connection will specify the default values for a connection such as CORS-behavior and caching policy, to ensure compatibility across platforms. On some services, such as Cloudflare Workers, specifying any value (inclluding the default values) will cause failure. Setting this to true will prevent any values being passed to the underlying API.```
I think it should be fine to add this argument to the JSONRPCProvider
construction, but we create these providers in a bunch of different places, so while this PR as currently written would fix using the contracts SDK directly, consumers of the SDK will still run into this error in other places in the SDK where we construct the JSONRPCProvider
on their behalf - likely just a few minutes later down their exploration of the JS SDK.
For your reference, every place that we need the new argument added are the same exact lines that were changed from JSONRPCProvider
to StaticJSONRPCProvider
in #537, plus one additional place that I didn't change in that PR because we couldn't use the StaticJSONRPCProvider for generic chains where we wouldn't necessarily be able to skip the chainId
pre-check behaviour here
Are you OK to make that change @joshdchang?
Hi, thanks for this! Do you want me to change it to StaticJSONRPCProvider in all the locations as well? This would overlap substantially with #537 and might lead to merge conflicts. Maybe this is best done in one PR? |
Sorry for the delayed response, and thanks so much for contributing! |
Replacing this with #646 which has the changes needed on all the providers. Thanks @joshdchang !!! |
Description
I was getting the following issue when trying to connect in a nodejs server-side webpack environment (in Next.js):
After doing some searching and testing, I figured out it was an bug from ethers.js with webpack. I tried the workaround from ethers-io/ethers.js#3536 (comment) and it fixed the issue. This PR only changes one line of code.
Type of change
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Checklist: