Use @nomiclabs/hardhat-etherscan verify a proxy contract,throw an error

when I use @nomiclabs/hardhat-etherscan verify a proxy contract,throw an error:

Error in plugin @nomiclabs/hardhat-etherscan: The contract you want to verify was compiled with solidity 0.8.2, but your configured compiler version is: 0.8.7.

Possible causes are:
  - You are not in the same commit that was used to deploy the contract.
  - Wrong compiler version selected in hardhat config.
  - The given address is wrong.
  - The selected network (rinkeby) is wrong.

The command to verify the contract is: npx hardhat verify --network rinkeby "contractAddress"

I Find the proxy contract's solidity version is ^0.8.0,and my implemention contract is 0.8.7, but the proxy contract is create by @openzeppelin/hardhat-upgrades,I can't edit it manually.

Please how can I solve the problem of this verification contract, thank you!

Please refer to our guide on verification:

By the output of your error i think you are trying to validate the proxy contract which as you can see doesn't work.

What you have to verify its the implementation contract. You can find the address of the implementation contract using the erc1967.getImplementationAddress and its the contract you have to verify.

After verifying the implementation address, then you can verify the proxy contract on bscscan, in the more options drop-down above the code window (the code should be automatically found by the block explorer) and select "is this a proxy?" option

erc1967.getImplementationAddress docs: https://docs.openzeppelin.com/upgrades-plugins/1.x/api-hardhat-upgrades#erc1967

2 Likes