wighawag / hardhat-deploy

hardhat deployment plugin
MIT License
1.19k stars 292 forks source link

ETHERSCAN_API_KEY takes precedence over hardhat config #338

Closed matmilbury closed 2 years ago

matmilbury commented 2 years ago

Describe the bug I have both ETHERSCAN_API_KEY and BSCSCAN_API_KEY specified in my .env file.

I also have this in my configuration:

const config: HardhatUserConfig = {
  solidity: "0.8.4",
  networks: {
    bsc: {
      chainId: 56,
      url: "https://bsc-dataseed.binance.org",
      accounts,
      verify: {
        etherscan: {
          apiKey: getEnvVariable("BSCSCAN_API_KEY"),
        },
      },
    },
    goerli: {
      url: "https://rpc.goerli.mudit.blog/",
      chainId: 5,
      accounts,
      verify: {
        etherscan: {
          apiKey: getEnvVariable("ETHERSCAN_API_KEY"),
        },
      },
    },
  },
}

When I run yarn hardhat --network bsc etherscan-verify, it tries to use ETHERSCAN_API_KEY instead of BSCSCAN_API_KEY.

Expected behavior hardhat config should take presedence over env variable.

wighawag commented 2 years ago

ETHERSCAN_API_KEY takes precedence (See : https://github.com/wighawag/hardhat-deploy/blob/240de8a0d70b313617ea179872c51457186ef91c/src/index.ts#L837-L841), use a different env variable name if you want to keep you config as is

matmilbury commented 2 years ago

@wighawag I know, I already looked in the code 😄

I suggest updating that behavior to:

const etherscanApiKey = 
   args.apiKey || 
   hre.network.verify?.etherscan?.apiKey || 
   hre.config.verify?.etherscan?.apiKey ||
   process.env.ETHERSCAN_API_KEY; 
wighawag commented 2 years ago

I disagree, env variable should take precedence over configuration files

matmilbury commented 2 years ago

I respectfully disagree.

But hey, you're the boss here.

I'd at least recommend documenting this bahvior to save folks from debugging and digging through the source code when the verification doesn't work the way they configured.

wighawag commented 2 years ago

This is expected behaviour in my opinion and what most tool do (git, node,....)

Simply because an env variable is more specific that a config file (env var are specific to a specific shell session, while a config file is more general)

I ll close this but feel free to create a PR for improving the doc