Upgrades Plugins: Etherscan verification for proxies

OpenZeppelin Upgrades Plugins are the recommended way to deploy and manage upgradeable contracts. They help you to make use of upgradeable proxy patterns that can involve a number of different contracts.

In the latest release of the Hardhat upgrades plugin, Etherscan verification for proxies is now available. This makes it easy to verify your upgradeable proxies and implementation contracts with a simple command.

This feature extends hardhat-etherscan’s verify task to completely verify a proxy. When you run verify with a proxy address, the Hardhat upgrades plugin will verify the proxy contract, the implementation contract and any proxy-related contracts. It will also link the proxy to the implementation's ABI on Etherscan.

To install the Hardhat upgrades plugin, see Using with Hardhat. If you already have the plugin installed, update to the latest version with: npm install @openzeppelin/hardhat-upgrades@latest

To verify a proxy that has been deployed by the plugin, see documentation for verify.

For more information about Etherscan verification in general, see How to verify a contract on Etherscan/BscScan/PolygonScan.

1 Like

Is hardhat-etherscan’s verify task the reason why redeploying an instance of an already verified proxy or affiliated contracts fails, because the contract initial proxy already verified?

Is verification in this case not connected to the newly deployed contract address?

Verifying is separate from deploying. One should not affect the other.

If the same proxy contract or related proxy contract was already verified on the network, the hardhat-upgrades verify task may show that the contract is already verified and Etherscan would show "Similar Match Source Code". You can consider this as a verified proxy.

If you need your proxy to show as an exact match rather than similar match on mainnet, contact Etherscan as described here.

@ericglau seems verification works fine when I use npx hardhat verify $address but fails when I execute the verification programmatically via await hre.run('verify:verify', { address }); with

Error in plugin @nomiclabs/hardhat-etherscan: The address provided as argument contains a contract, but its bytecode doesn't match any of your local contracts.

Any thoughts on why would that happen?

@kargakis The task extends hardhat-etherscan's verify, not verify:verify. So to run it programmatically, use await hre.run('verify', { address: <proxy contract address> })

1 Like

Thanks @ericglau, did the trick!

What about the Sourcify task of Hardhat? It seems this one definitely requires a pure implementation artifacts to work, as it would throw an error with the created artifacts (which contain both proxy and implementation ABIs).

verifying MyContract (0xabcd... on chain 44787) ...
{"error":"Contract name: MyContract. The deployed and recompiled bytecode don't match."}

@Marcel_Jackisch Sourcify verification isn't supported with the plugins at the moment. Can you open an issue on https://github.com/OpenZeppelin/openzeppelin-upgrades/issues to request this feature and provide details on your expected use case? Thanks.