Etherscan – Fixing ‘TypeError: etherscan.apiKey.trim Is Not a Function’ with Multiple API Keys in Hardhat

contract-verificationetherscanhardhat

greeting

the next link continue part about Multiple API keys and alternative block explorers

https://github.com/nomiclabs/hardhat/tree/master/packages/hardhat-etherscan#multiple-api-keys-and-alternative-block-explorers

when try apply that on my code face "TypeError: etherscan.apiKey.trim is not a function"

1- I add values of api key as environments variables.

2- I use @nomiclabs/hardhat-etherscan plugin for verifying process.

3- I use next command to verify the smart contract:

npx hardhat verify --network matic contract address

that's the code before add multi api key(work correct, without any problem for rinkepy and polygon)

module.exports = {
defaultNetwork: "matic",
networks: {

    rinkeby: {
        url: RINKEBY_RPC_URL,
        accounts: {
            mnemonic: MNEMONIC,
        },
        saveDeployments: true,
    },

    matic: {
        url: Mumbai_RPC_URL,
        accounts: {
            mnemonic: MNEMONIC,
        },
        saveDeployments: true,
    },
},

etherscan: {
    apiKey: ETHERSCAN_API_KEY,
},

next code after add multi api key can help me to know what wrong in it

module.exports = {
defaultNetwork: "matic",
networks: {

    rinkeby: {
        url: RINKEBY_RPC_URL,
        accounts: {
            mnemonic: MNEMONIC,
        },
        saveDeployments: true,
    },

    matic: {
        url: Mumbai_RPC_URL,
        accounts: {
            mnemonic: MNEMONIC,
        },
        saveDeployments: true,
    },
},

etherscan: {
    apiKey: {
              rinkeby: ETHERSCAN_API_KEY,
              polygonMumbai: POLYGONSCAN_API_KEY,
    }
},

Best Answer

I got this same error (on rinkeby network). Fixed by removing the @nomiclabs/hardhat-etherscan package, then reinstalling it:

npm remove @nomiclabs/hardhat-etherscan

then

npm install --save-dev @nomiclabs/hardhat-etherscan

hope that helps!

Related Topic