NomicFoundation / hardhat

Hardhat is a development environment to compile, deploy, test, and debug your Ethereum software.
https://hardhat.org
Other
7.17k stars 1.38k forks source link

Issue: Contract Verification Fails on Etherscan but Succeeds on Blockscout #5677

Closed anirudhmakhana closed 1 week ago

anirudhmakhana commented 2 weeks ago

Version of Hardhat

2.22.9

What happened?

I deployed a contract using Hardhat and attempted to verify it on both Etherscan and Blockscout. The verification process works seamlessly on Blockscout, but it fails on Etherscan despite using the same deployment configuration.

I also asked a few others on my team try it out and they faced the same issue.

Configurations Below are the configurations I used: Etherscan Configuration (Verification Fails):

import "@nomicfoundation/hardhat-toolbox";
import "@nomiclabs/hardhat-ethers";
import "hardhat-deploy";
import dotenv from "dotenv";

dotenv.config();

const PRIVATE_KEY = process.env.PK!;

const config: HardhatUserConfig = {
  solidity: "0.8.20",
  namedAccounts: {
    deployer: {
      default: 0,
    },
  },
  networks: {
    hardhat: {
      forking: {
        url: "https://eth-sepolia.g.alchemy.com/v2/myapiKey",
      },
    },
    sepolia: {
      url: "https://eth-sepolia.g.alchemy.com/v2/myapiKey",
      accounts: [PRIVATE_KEY],
      chainId: 11155111,
    },
  },
  etherscan: {
    apiKey: {
      sepolia: "apiKeyFromEtherscan",
    },
  },
};

export default config;

Result:

$ npx hardhat verify --network sepolia 0x23D5C963eFbE897483D4451b6e489A66371120B3 "0xd5e28344c86c7da2c291e20603aeb2ec624dd3c7" --show-stack-traces
Nothing to compile
No need to generate any newer typings.
DEPRECATION WARNING: 'hardhat-etherscan' has been deprecated in favor of 'hardhat-verify'. You can find more information about the migration in the readme.
Error in plugin @nomiclabs/hardhat-etherscan: Invalid API Key

Blockscout Configuration (Verification Succeeds):

import "@nomicfoundation/hardhat-toolbox";
import "@nomiclabs/hardhat-ethers";
import "hardhat-deploy";
import dotenv from "dotenv";

dotenv.config();

const PRIVATE_KEY = process.env.PK!;

const config: HardhatUserConfig = {
  solidity: "0.8.20",
  namedAccounts: {
    deployer: {
      default: 0,
    },
  },
  networks: {
    hardhat: {
      forking: {
        url: "https://eth-sepolia.g.alchemy.com/v2/myapiKey",
      },
    },
    sepolia: {
      url: "https://eth-sepolia.g.alchemy.com/v2/myapiKey",
      accounts: [PRIVATE_KEY],
      chainId: 11155111,
    },
  },
  etherscan: {
    apiKey: {
      sepolia: "xxx",
    },
    customChains: [
      {
        network: "sepolia",
        chainId: 11155111,
        urls: {
          apiURL: "https://eth-sepolia.blockscout.com/api",
          browserURL: "https://eth-sepolia.blockscout.com",
        },
      },
    ],
  },
};

export default config;

Result

No need to generate any newer typings.
Successfully submitted source code for contract
contracts/Faucet.sol:TokenFaucet at 0x23D5C963eFbE897483D4451b6e489A66371120B3
for verification on the block explorer. Waiting for verification result...

Successfully verified contract TokenFaucet on Etherscan.
https://eth-sepolia.blockscout.com/address/0x23D5C963eFbE897483D4451b6e489A66371120B3#code

Minimal reproduction steps

Steps to Reproduce

  1. Deploy a contract on the Sepolia network using Hardhat.
  2. Attempt to verify the contract on Etherscan using the configuration provided.
  3. Observe that the verification fails on Etherscan.
  4. Attempt the same verification on Blockscout using the alternative configuration.
  5. Observe that the verification succeeds on Blockscout.

Search terms

etherscan invalid api

superposition commented 2 weeks ago

same rn

anirudhmakhana commented 2 weeks ago

No longer facing this issue, but i feel this is related to etherscan API, would be good to get some insights here before i close this

kanej commented 1 week ago

I suspect this was a temporary etherscan issue. We had a cluster of reports on the same day, then it quickly resolved.