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

Incorrect evaluation of the etherscanApiKey when verifying contracts. #502

Closed
ivanzhelyazkov opened this issue Dec 11, 2023 · 1 comment
Closed

Comments

@ivanzhelyazkov
Copy link
Contributor

ivanzhelyazkov commented Dec 11, 2023

Describe the bug
Incorrect evaluation of the etherscanApiKey when verifying contracts.

To Reproduce
Steps to reproduce the behavior:
Attempt to verify a contract on a different network than mainnet (base, arbitrum, polygon, etc.) with correctly set hardhat configuration (hh.network.verify.etherscan.apiKey) and valid api key leads to error: failed to submit : "NOTOK" : "Invalid API Key"

Expected behavior
Should verify contract as expected.

** More context **
The code down below (line 857 in index.ts) evaluates the etherscanApiKey based on 4 fields in the order:

  1. command line argument apiKey
  2. If ETHERSCAN_API_KEY is present
  3. hre.network.verify.etherscan.apiKey
  4. hre.config.verify.etherscan.apiKey

Which means if you have set ETHERSCAN_API_KEY for mainnet, and an api key for another network in the hardhat config, the api key deduced will be the mainnet one and the verification will fail with invalid key.

 .setAction(async (args, hre) => {
    const etherscanApiKey =
      args.apiKey ||
      process.env.ETHERSCAN_API_KEY ||
      hre.network.verify?.etherscan?.apiKey ||
      hre.config.verify?.etherscan?.apiKey;
    if (!etherscanApiKey) {
      throw new Error(
        `No Etherscan API KEY provided. Set it through command line option, in hardhat.config.ts, or by setting the "ETHERSCAN_API_KEY" env variable`
      );
    }
    
    const solcInputsPath = await deploymentsManager.getSolcInputPath();
    await submitSources(hre, solcInputsPath, {
      contractName: args.contractName,
      etherscanApiKey,
      license: args.license,
      fallbackOnSolcInput: args.solcInput,
      forceLicense: args.forceLicense,
      sleepBetween: args.sleep,
      apiUrl: args.apiUrl || hre.network.verify?.etherscan?.apiUrl,
      writePostData: args.writePostData,
    });
  });

versions

  • hardhat-deploy [0.11.44]
  • hardhat [2.15.0]
  • nodejs [16.18.01]
@ivanzhelyazkov
Copy link
Contributor Author

Fixed docs for the evaluation in #504

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant