Error verifying proxy with plugin @nomiclabs/hardhat-etherscan

Good job, and I am following this tutorial (OpenZeppelin Upgrades: Step by Step Tutorial for Hardhat), but I met some problems, when I first deployed the proxy contract, it generated three contracts, but when I deployed it again, it only generated one contract, and I can not verify the contract. Threw out the error:

Error in plugin @nomiclabs/hardhat-etherscan: The bytecode retrieved could not have been generated by any of the selected compilers.
The expected version is 0.6.8.
The selected compiler version is: 0.6.12

Possible causes are:
  - Wrong compiler version selected in hardhat config.
  - The given address is wrong.
  - The selected network (kovan) is wrong.

All my contracts, scripts, and config is at here: https://gist.github.com/Skyge/a7476b10e080af9fb75cc2c3c38d45f9

my commands are:

npx hardhat run deploy.js --network kovan
npx hardhat verify --network kovan ADDRESS

BTW, how to write a script of the type of .ts to deploy, cause

const token = await upgrades.deployProxy(Token, ["Mock Token", "MT"], { initializer: 'initialize' });

will throw out an error:

error TS2304: Cannot find name 'upgrades'.
1 Like

Hi @Skyge,

Thanks for checking out the tutorial and the all the details of what you used.

I had trouble verifying the proxy as I originally had OpenZeppelin Contracts 3.1 rather than OpenZeppelin Contracts 3.2 as a dependency. I verified in a separate project.

I did the following using your Token contract and a slightly modified hardhat configuration:

Deploy

$ npx hardhat run --network kovan scripts/deploy.js
Creating Typechain artifacts in directory types for target ethers-v5
Successfully generated Typechain artifacts!
Deploying contracts with the account: 0xEce6999C6c5BDA71d673090144b6d3bCD21d13d4
Account balance: 100000000000000000
Token address: 0x639E41d0E23b56b91deA5dC39A92A3c58Dbf0062

Verify Implementation (Token.sol)

Implementation address obtained from .openzeppelin/kovan.json

$ npx hardhat verify --network kovan 0x4E37CC7B6d8097a22150CDFa7dcC133C245D5979
Nothing to compile
Creating Typechain artifacts in directory types for target ethers-v5
Successfully generated Typechain artifacts!
Successfully submitted source code for contract
contracts/Token.sol:Token at 0x4E37CC7B6d8097a22150CDFa7dcC133C245D5979
for verification on etherscan. Waiting for verification result...
Successfully verified contract on etherscan

When we first deploy three contracts are deployed:

  1. Implementation: https://kovan.etherscan.io/tx/0xd3520b35bac0319888b945bc50c58572647ecb5e2ac7c69d94c92d62b611afc0
  2. ProxyAdmin: https://kovan.etherscan.io/tx/0x1050022949a2470a771e0fb63657b81a6756cb52c85edd945d1968e8490db269
  3. Proxy: https://kovan.etherscan.io/tx/0x2d398a2677df78b980cd58f1226aa7447f1655ad6efef345e59c806ece393f46

Rerunning deploy only deploys a proxy, as there is only one ProxyAdmin per network deployed by your project and the implementation contract has already been deployed:

  1. Proxy:
    https://kovan.etherscan.io/tx/0xc541cae6fd6547f4d2fb39716ee977fe5083b766498f9ae06ddac5d507cd0462

From: https://docs.openzeppelin.com/upgrades-plugins/1.x/faq#what-is-a-proxy-admin

A ProxyAdmin is a contract that acts as the owner of all your proxies. Only one per network gets deployed.

$ npx hardhat run --network kovan scripts/deploy.js
Creating Typechain artifacts in directory types for target ethers-v5
Successfully generated Typechain artifacts!
Deploying contracts with the account: 0xEce6999C6c5BDA71d673090144b6d3bCD21d13d4
Account balance: 97484402000000000
Token address: 0x903303BfA4Def0Fc4F474b965DC81F33CB87b550

I verified the proxy and the ProxyAdmin using Hardhat Etherscan plugin, similar to: Verify Upgrades Plugins proxy on Etherscan but using OpenZeppelin Contracts 3.2

Verify ProxyAdmin

$ npx hardhat verify --network kovan 0xe5452ae84dd4b374e3bc6a3e5b3a63584d619c83
Nothing to compile
Successfully submitted source code for contract
contracts/proxy/ProxyAdmin.sol:ProxyAdmin at 0xe5452ae84dd4b374e3bc6a3e5b3a63584d619c83
for verification on etherscan. Waiting for verification result...
Successfully verified contract on etherscan

Verify Proxy

(using OpenZeppelin Contracts 3.2)

$ npx hardhat verify --constructor-args arguments.js --network kovan 0x639E41d0E23b56b91deA5dC39A92A3c58Dbf0062
Compiling 3 files with 0.6.8
Compilation finished successfully
Successfully submitted source code for contract
contracts/proxy/AdminUpgradeabilityProxy.sol:AdminUpgradeabilityProxy at 0x639E41d0E23b56b91deA5dC39A92A3c58Dbf0062
for verification on etherscan. Waiting for verification result...
Successfully verified contract on etherscan

I will have to find out how to write typescript to deploy. I have created a new topic for this: How to write the Typescript to deploy?

1 Like

Really thanks for your confirmation, I found out I made a mistake, I tried to verify the AdminUpgradeabilityProxy by token contract address, so it failed.

1 Like

Hi @Skyge,

Verification is still hard. I had issues because I used OpenZeppelin Contracts 3.1 rather than 3.2.

Easy mistakes to make.

Okay, thanks for your reminder, I will pay attention to the version of the dependency.

1 Like