-
-
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
Cannot call contract methods using Cloudflare Workers #3763
Comments
That line is a call to |
I've set the version to 17.9.1 but I don't have any control over how it's built. |
Cloudflare Workers must be built on a separate host, and then uploaded, since the service only accepts a single-file application (unless there have been recent changes?), so there must be a bundler config (web pack or rollup) somewhere... |
Then it's as default as it comes haha. |
The following pages goes over the bundling of a worker using the latest version of wrangler: Maybe there is a setting I can try/tweak. |
Is there any way you can see the generated code? |
Yes, but I'd rather not post it here publicly. |
You could also reproduce it by creating a project with Wrangler and use the following code/settings: File: export default
{
async fetch(request, env, ctx)
{
const { JsonRpcProvider, Contract, Wallet, formatEther } = await import('ethers');
const CONTRACT = {
address: "someAddressHere",
abi: [
'function balanceOf(address account) external view returns (uint)'
]
}
// Provider and wallet
const provider = new JsonRpcProvider(env.RPC_URL);
const wallet = new Wallet(env.PRIVATE_KEY, provider);
const contract = new Contract(CONTRACT.address, CONTRACT.abi, provider);
const result = await contract.balanceOf(wallet.address).call();
console.log(result);
},
}; File:
And using |
I've got a few other things that are high priority I'm working on now, but you can send me an e-mail to me@ricmoo.com. If you can produce a small concise example with the generated code, that's always appreciated too. ;) |
I'll send you the generated code for the example above! |
Quick side note. I've downgraded to the latest v5 version and that one does work, so maybe that narrows the search for the bug. Let me know if you need a copy of the generated code. |
This is the same problem as #3749, which I’ve been updating, so I’m going to close this issue to help keep all the discussion in one place. I’m pretty sure I understand the problem now and will get v6.2.0 out asap to address this. Thanks! :) |
This has been addressed in v6.2.0. Please try it out and let me know if there are any problems. :) |
Ethers Version
6.0.2
Search Terms
cloudflare, code generation, Code generation from strings disallowed for this context
Describe the Problem
When using CloudFlare Workers I can't call methods on a contract.
A simple
await contract.balanceOf(wallet.address).call()
doesn't work in my case.The error I get is
Code generation from strings disallowed for this context
.Ideally, this would get solved in the package itself (if it is even related to an internal bug).
Otherwise, if I need to use a workaround that would be totally fine too.
Code Snippet
Contract ABI
['function balanceOf(address account) external view returns (uint)']
Errors
Environment
Other (please specify)
Environment (Other)
CloudFlare Workers
The text was updated successfully, but these errors were encountered: