-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
cloudflare worker fails with some parameters that ethers.js harcode #1886
Comments
Ugh. :( The problem is allowing them to be overrides would balloon the size of the code, as those would all need non-default behaviours implemented in the node They are the default values, so I am inclined to remove them and let the defaults take over, but that may break something else. I need to investigate this further. Ideally, Cloudflare would ignore values if they are the default. :s |
I'm adding a new field to the options (which will be ignored in Node) called This will be in the next minor bump, which should be coming out soon. I've completed 22 of the 30 issues I'm rolling into this release, so it's getting close. :) |
Hi @ricmoo I see that commit Including the following code at any point in the durable object will cause the request to fail. const ethereumNode = ethers.providers.InfuraProvider.getWebSocketProvider(
'mainnet', {
projectId: '...'
}
); This throws the error I am on |
You might need to adjust your bundler settings? The I forgot the expose the skip flag higher up the stack though, so it may still not work with http. I need to rectify that this week. |
(I’m frantically trying to get a v6 beta out, which will resolve a lot of these bundler issues and create much smaller code foot prints; sorry I haven’t been as responsive to issues lately as I try to get this ready) |
Thanks for the quick reply! Been following a lot of your other issues here; I'm very excited for v6 with the tree shaking improvements. This could very well be an issue with my bundler; I'm quite a novice when it comes to that. I will go look into the Another thought I had: can I perhaps use the browser version of |
@ricmoo so I played around today with the ESM build of Ethers on a direct browser page <script type="module">
import { ethers } from "./ethers-esm.js";
... and the Side note: I think CORS on the CDN is broken again so I had to ESM script locally on my testing server like this. |
Hi @ricmoo ! I really appreciate your work and totally fell in love with Ethers. Any idea when v6 beta (or even alpha 😄 ) could be released, addressing this Cloudflare Worker issue? We have created a simple Ethereum/Polygon API intended for Cloudflare workers and we would love to try it out outside local environments. We are using JsonRpcProvider with Moralis JSON RPC nodes. Any estimations would be highly appreciated. Thanks! |
as a workaround I perform a post-process step after build :
Note: using esbuild to generate |
@wighawag Wow, thank you! I am using webpack and this is my webpack config, based on your suggestion:
I needed to install Thank you @wighawag and thank you @ricmoo for the amazing package. |
Yeah, I messed up an didn’t expose it high enough up. I might have to make another minor bump to expose it. I was hoping to get v6 out sooner too though. Let me look into this. |
@ricmoo I understand that the workaround is there but unusable from any provider connection ? Any ETA ? Thanks ! |
This is great news! I am working on a smol tool to easily resolve ENS addresses via cloudflare workers, so really looking forward to unblocking this :) |
Hi @DanielAGW Tried looking at doing this but I still get the same errors just wondering how you're using ethers I've got
with the response of
Thanks |
I think that it has been fixed by @ricmoo but not included in an NPM version. |
Thank you so much! This fixed it for me! |
This is now available in v5.6. I've tried it out and am loving Cloudflare Workers. To use it, connect to your provider setting the const provider = new StaticJsonRpcProvider({
url: URL,
skipFetchSetup: true
}); Let me know if you have any issues! |
This was added, so I'll close it. Please re-open or create a new issue if there are any problems. Thanks! :) |
Modified the ethers provided to StaticJsonRpcProvider. This issue shows it why. ethers-io/ethers.js#1886
cloudflare worker mimic the behavior of a service worker, as such it is like a limited browser environment.
unfortunately it does not implement all parameters of the
fetch
api making it fails with ethers.js due to these lines:ethers.js/packages/web/src.ts/browser-geturl.ts
Lines 17 to 21 in ce8f1e4
While the
redirect
field works, the other do not and I get a respective error for each:The 'credentials' field on 'RequestInitializerDict' is not implemented.
The 'cache' field on 'RequestInitializerDict' is not implemented.
The 'mode' field on 'RequestInitializerDict' is not implemented.
The 'referrer' field on 'RequestInitializerDict' is not implemented.
Would be great if we could override the default behavior here.
The text was updated successfully, but these errors were encountered: