2

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,
    }
},
2
  • The code you pasted is not the code failing you need ot check where are you trimming the apiKey as it says on the error
    – Julissa DC
    Commented Jan 31, 2022 at 13:50
  • i add values of api key as environments variables, so there's no trim happend
    – naive2022
    Commented Jan 31, 2022 at 20:03

3 Answers 3

4

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!

2

The use of multiple API keys and alternative block explorers is only available since @nomiclabs/hardhat-etherscan version 3.0.0. That's why the suggestion made by "panda" works (install latest version).

ps-i would like to add only a comment by not possible for me yet.

1

Quite likely https://github.com/nomiclabs/hardhat/issues/1117#issuecomment-779213915 will help you as it solved this for me.

If not, you may try to set mumbai as default network and just leave the signle apiKey..anyway it seems you have not defined the polygon testnet connection details at all.

1
  • thanks a lot. matic is the polygon testnet, and i add the details as environments variables. i already finish work with rinkeby and i will only need one api (polygon api) so i will not face same problem again. just try understand what wrong to avoid it in the feature.
    – naive2022
    Commented Feb 6, 2022 at 17:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.