-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
getNetwork returns "could not detect network" when running as a Cloudflare Worker #1757
Comments
Can you manually call |
Cloudflare is just an example here.... I get the same result when I use my own node. (Didn't want to post the address publicly here) anyways the returned chainId looks correct when calling both cloudflare and my own node via curl: |
If the node is offline or not reachable for some reason then you'll get the error If you're still facing this issue, can you try if this runs or what error do you get?
|
It is hard to debug some of these issues, especially with Cloudflare. They often dial-up their anti-bot rules, during which time if the call looks like it is coming from a script (e.g. the user agent matches a vague regex, or certain headers are missing) they block it. It is often intermittent, but if you can put a few I generally advise against the Cloudflare endpoints as they have often been unreliable… :s |
I’m facing a similar issue still. I’m writing my code in cloudflare wrangler typescript template to query a ERC20 function of a smart contract using “ether.js”. Actually, it doesn’t matter what provider I use (I tried both “infura”, and “cloudflare-eth”), only when I invoke the ERC20 function "await contract.totalSupply()" do I get the same error as above. By the way, I’m using webpack to bundle everything.
A while ago, I worked around this issue by byte-encoding the function and passing it to the method ‘eth_call’ (my provider was infura in this case), but this is not sustainable. See below.
Any explanation would be appreciated. |
Did you get the expected response for the |
@zemse yes I got the expected response for
it works and I get the expected output as well |
Can you add |
I'm having this exact issue, see code and debug below:
Requesting with curl or outside of CF Worker works as expected |
I was not familiar with CF worker. Does it execute your code in some remote environment? Are you able to reach the const message = await fetch(
"https://eth-rinkeby.alchemyapi.io/v2/API_KEY",
{
method: "POST",
body: JSON.stringify({
jsonrpc:2.0,
method:'eth_blockNumber',
params:[],
id:1
}
)
}) |
Yes, this works no problem. As a temporary workaround I implemented my own class which uses the underlying Here is the base templates I used, very minimal webpack setup that listens for two routes. https:/cloudflare/worker-template-router |
I've just tried adding |
Thanks for sharing your workaround. I too am attempting to use Ethers with Cloudflare Workers and am running into the same issue. |
I am encountering the same problem. The method that I use is providers.resolveName(). |
Hitting the same issue. I added
Trying
Trying Passing the chainId itself to the constructor like Using Infura as the provider endpoint gave same results. Happy to help debug or get you setup with a Workers test environment if that helps... |
@TimTinkers do you have any more examples using your work around. The method I'm trying to call takes two params, a string and a uint256 and it doesn't end up getting formatted properly. Playing encoder/decder tools, there's a missing 0x between the function signature and the params in the data field... |
Hi @stevenpack, I think you perhaps mistook me for @0x62 who published a workaround. In a nutshell though, this all boils down to using |
You're right @TimTinkers , thanks for clarifying and thanks @0x62 for the work around. Worked me once I added the latest block property.
Will drop a comment on your gist. |
same problem using provider.getNetwork(). I guess I have to use fetch , huh |
Closing older issues. But if this is still happening in v6, please re-open or start a new issue. Side note though; I personally use ethers v6 in Cloudflare Workers without issue now. Thanks! :) |
I'm seeing a strange issue only when I use Ethers as a Cloudflare worker. I can create the provider, but then i'm getting a noNetwork bug when it runs:
results in the following:
This only happens when running as a Cloudflare worker. When running in the browser or repl this code works fine.
I've created a branch to minimally reproduce this bug here: https:/fafrd/ens-reverse-lookup/tree/ethers-bug. See handleRequest.js.
The text was updated successfully, but these errors were encountered: