Skip to content
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

Can't connect to goerli via the default provider #3979

Open
GildedHonour opened this issue Apr 14, 2023 · 13 comments
Open

Can't connect to goerli via the default provider #3979

GildedHonour opened this issue Apr 14, 2023 · 13 comments
Assignees
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published. v6 Issues regarding v6

Comments

@GildedHonour
Copy link

GildedHonour commented Apr 14, 2023

Ethers Version

6.x

Search Terms

No response

Describe the Problem

Why doesn't this code work in 5.7.2

const provider = ethers.getDefaultProvider("goerli", {
  etherscan: process.env.ETHERSCAN_API_KEY,
});

and no longer does in 6.x

TypeError: unsupported network (argument="network", value="goerli", code=INVALID_ARGUMENT, version=6.2.3)

?

How's it unsupported? According to the documentation of the v6, it should work.

How to connect to "goerli" via the default provider?

And the same error will get thrown for "sepolia" as well.

Code Snippet

No response

Contract ABI

No response

Errors

No response

Environment

No response

Environment (Other)

No response

@GildedHonour GildedHonour added investigate Under investigation and may be a bug. v6 Issues regarding v6 labels Apr 14, 2023
@ricmoo
Copy link
Member

ricmoo commented Apr 14, 2023

It should definitely be supported. I’ll look at this first thing in the morning.

@jeftarmascarenhas-hotmart

@GildedHonour Are you trying use getDefaultProvider on Browser or Server?

@jeftarmascarenhas-hotmart

@ricmoo Why options parameter is with type any?
getDefaultProvider(network: string | Networkish | WebSocketLike, options?: any // this): AbstractProvider

My question is because @GildedHonour is using etherscan as a options but option parameter is any and has no treat etherscan within options.

const provider = ethers.getDefaultProvider("goerli", {
  etherscan: process.env.ETHERSCAN_API_KEY,
});

@GildedHonour
Copy link
Author

@jeftarmascarenhas-hotmart on a server

@ricmoo
Copy link
Member

ricmoo commented Apr 29, 2023

I suppose it should have been Record<string, any>, but for each backend, the possibly types of parameters can vary greatly.

@jeftarmascarenhas
Copy link

@GildedHonour on a server
I think that isn't working on a server. For me isn't working.

const provider = ethers.getDefaultProvider("goerli", {
  etherscan: process.env.ETHERSCAN_API_KEY,
});

@ricmoo
Copy link
Member

ricmoo commented Apr 29, 2023

Can you provide the error?

@jeftarmascarenhas
Copy link

I suppose it should have been Record<string, any>, but for each backend, the possibly types of parameters can vary greatly.

Yes, that true.

What do you think about change any to Record<string, any>?
Sorry, I was configuring it's wrong and I think @GildedHonour configured wrong(I think) too.

# needs add a provider like alchemy if you're working on server(ex: Node.js)
const provider = ethers.getDefaultProvider("goerli", {
  etherscan: process.env.ETHERSCAN_API_KEY,
alchemy...
});

@ricmoo
Copy link
Member

ricmoo commented Apr 29, 2023

So, that can’t change in v6, as that isn’t backwards compatible. Ethers is used by a large number of projects, so maintaining backward compatibility is important. :)

@jeftarmascarenhas
Copy link

So, that can’t change in v6, as that isn’t backwards compatible. Ethers is used by a large number of projects, so maintaining backward compatibility is important. :)

Ok, I understand.

I create this discussion about Date below
#4019

Thanks

@jeftarmascarenhas
Copy link

jeftarmascarenhas commented Apr 30, 2023

@ricmoo follow the error when user ethers.getDefaultProvider on server
This code below is the implementation
Screen Shot 2023-04-29 at 22 21 45

When code above is running

TypeError: unsupported network (argument="network", value="goerli", code=INVALID_ARGUMENT, version=6.3.0)
    at makeError (/Users/jeffmascarenhas/blockchain/project-contributies/ethersjs-test/node_modules/ethers/src.ts/utils/errors.ts:656:21)
    at assert (/Users/jeffmascarenhas/blockchain/project-contributies/ethersjs-test/node_modules/ethers/src.ts/utils/errors.ts:680:25)
    at assertArgument (/Users/jeffmascarenhas/blockchain/project-contributies/ethersjs-test/node_modules/ethers/src.ts/utils/errors.ts:692:5)
    at new CloudflareProvider (/Users/jeffmascarenhas/blockchain/project-contributies/ethersjs-test/node_modules/ethers/src.ts/providers/provider-cloudflare.ts:21:23)
    at Object.getDefaultProvider (/Users/jeffmascarenhas/blockchain/project-contributies/ethersjs-test/node_modules/ethers/src.ts/providers/default-provider.ts:52:28)
    at main (/Users/jeffmascarenhas/blockchain/project-contributies/ethersjs-test/index.ts:16:27)
    at Object.<anonymous> (/Users/jeffmascarenhas/blockchain/project-contributies/ethersjs-test/index.ts:32:1)
    at Module._compile (node:internal/modules/cjs/loader:1126:14)
    at Module.m._compile (/Users/jeffmascarenhas/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/index.ts:1618:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1180:10) {
  code: 'INVALID_ARGUMENT',
  argument: 'network',
  value: 'goerli'
}
0.168293502174358329

I think that validation is wrong.
If we remove !== "-" it's correct, I don't understand this condition !== "-"

if (options.alchemy !== "-") {
        try {
            providers.push(new AlchemyProvider(network, options.alchemy));
        } catch (error) { console.log(error); }
    }

    if (options.ankr !== "-" && options.ankr != null) {
        try {
            providers.push(new AnkrProvider(network, options.ankr));
        } catch (error) { console.log(error); }
    }

    if (options.cloudflare !== "-") {
        try {
            providers.push(new CloudflareProvider(network));
        } catch (error) { console.log(error); }
    }

    if (options.etherscan !== "-") {
        try {
            providers.push(new EtherscanProvider(network, options.etherscan));
        } catch (error) { console.log(error); }
    }

    if (options.infura !== "-") {
        try {
            let projectId = options.infura;
            let projectSecret: undefined | string = undefined;
            if (typeof(projectId) === "object") {
                projectSecret = projectId.projectSecret;
                projectId = projectId.projectId;
            }
            providers.push(new InfuraProvider(network, projectId, projectSecret));
        } catch (error) { console.log(error); }
    }
/*
    if (options.pocket !== "-") {
        try {
            let appId = options.pocket;
            let secretKey: undefined | string = undefined;
            let loadBalancer: undefined | boolean = undefined;
            if (typeof(appId) === "object") {
                loadBalancer = !!appId.loadBalancer;
                secretKey = appId.secretKey;
                appId = appId.appId;
            }
            providers.push(new PocketProvider(network, appId, secretKey, loadBalancer));
        } catch (error) { console.log(error); }
    }
*/
    if (options.quicknode !== "-") {
        try {
            let token = options.quicknode;
            providers.push(new QuickNodeProvider(network, token));
        } catch (error) { console.log(error); }
    }

@ricmoo
Copy link
Member

ricmoo commented May 7, 2023

I've found the issue and am working on a solution.

There are two problems happening that are confusing things.

First, I console.log superfluous errors in that method, which I've removed locally. So, the reported error is masking the actual issue (the error is only in the console, it isn't actually affecting anything).

The real problem seems that Alchemy has broken the ethers API key, which means that the initial sync needed by the fallback provider is failing.

This is a problem; the FallbackProvider should be more resilient against a backend being down (that's its entire purpose), so I'm working on a fix for this, where a backend that reports a fatal error will get put in a penalty box for some period of time.

As a quick work around, you can disable Alchemy:

const provider = ethers.getDefaultProvider("goerli", { alchemy: "-" });

By setting any backend to a "-", the backend will be skipped.

@ricmoo ricmoo added bug Verified to be an issue. on-deck This Enhancement or Bug is currently being worked on. and removed investigate Under investigation and may be a bug. labels May 7, 2023
@ricmoo
Copy link
Member

ricmoo commented May 20, 2023

I've added a feature to the FallbackProvider which will exclude backends that result in a fatal error. It can be expanded in the future to let it re-attempt in the future, but for now a failed backend is permanently removed. A lot of additional stats are tracked for future use too, to enable more robust dispatching heuristics.

Please ty it out and let me know if there are any further issues. :)

@ricmoo ricmoo added fixed/complete This Bug is fixed or Enhancement is complete and published. and removed on-deck This Enhancement or Bug is currently being worked on. labels May 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published. v6 Issues regarding v6
Projects
None yet
Development

No branches or pull requests

4 participants