Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use @nomiclabs/hardhat-etherscan for Etherscan verification #125

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

michalinacienciala
Copy link
Contributor

@nomiclabs/hardhat-etherscan exposes verification functions for Etherscan that
are recommended by the hardhat team.

See https://hardhat.org/hardhat-runner/plugins/nomiclabs-hardhat-etherscan

Previously we were using etherscan-verify from hardhat-deploy plugin, which
had problems with verification of some contracts.

Apart from this change we also do a cleanup of supported testnets - we remove
configuration related to Ropsten and Rinkeby testnets, as they're
going to be deprecated soon
and we've transitioned to using Goerli testnet.

@nomiclabs/hardhat-etherscan exposes verification functions for Etherscan that
are recommended by the hardhat team.

See https://hardhat.org/hardhat-runner/plugins/nomiclabs-hardhat-etherscan

Previously we were using `etherscan-verify` from `hardhat-deploy` plugin, which
had problems with verification of some contracts.

Note: We introduce temporary changes helping with testing of the new
verification method. They will be removed before merge to `main`.
Previously used `0.9.29` version was causing conflicts with the
`@nomiclabs/hardhat-etherscan` plugin (`Property 'etherscan' must be of type
'EtherscanUserConfig', but here has type '{ apiKey?: string; }'` during `npm
pubish`).
According to wighawag/hardhat-deploy#257 upgrading
`hardhat-deploy` to version `0.10.0` or higher should fix the issue.
Without it, deployment/verification was throwing following message:
```
Verifying contract 0x... on Etherscan...
Nothing to compile
NomicLabsHardhatPluginError: More than one contract was found to match the
deployed bytecode.
Please use the contract parameter with one of the following contracts:
  * contracts/governance/BaseTokenholderGovernor.sol:BaseTokenholderGovernor
  * contracts/governance/TokenholderGovernor.sol:TokenholderGovernor
  * contracts/test/TestGovernorTestSet.sol:TestTokenholderGovernor

For example:

  hardhat verify --contract contracts/Example.sol:ExampleContract <other args>

If you are running the verify subtask from within Hardhat instead:

  await run("verify:verify", {
    <other args>,
    contract: "contracts/Example.sol:ExampleContract"
  };
```
Without the change, the deployment/verification was logging:
```
Verifying contract 0x... on Etherscan...
Nothing to compile
NomicLabsHardhatPluginError: Failed to send contract verification request.
Endpoint URL: https://api-goerli.etherscan.io/api
Reason: The Etherscan API responded that the address 0x... does not have
bytecode.
This can happen if the contract was recently deployed and this fact hasn't
propagated to the backend yet.
Try waiting for a minute before verifying your contract. If you are invoking
this from a script, try to wait for five confirmations of your contract
deployment transaction before running the verification subtask.
```
Both testnets are soon to be deprecated
(https://blog.ethereum.org/2022/06/21/testnet-deprecation). We've transisioned
to using Goerli testnet instead and we no longer need to have any code relating
to Ropsten/Rinkeby.
@michalinacienciala
Copy link
Contributor Author

@cygnusv
Copy link
Member

cygnusv commented Sep 19, 2022

FWIW, I've had issues with v3.1.0 in this project (see commit bf90cd5), so I had to pin 3.0.4.

@michalinacienciala
Copy link
Contributor Author

FWIW, I've had issues with v3.1.0 in this project (see commit bf90cd5), so I had to pin 3.0.4.

Do you remember what kind of issues was it, @cygnusv? Some problem with deploy/verification? I was able to deploy and verify contracts without issues...

@cygnusv
Copy link
Member

cygnusv commented Sep 19, 2022

Thank goodness I never close my console tabs. Found it:

david@Davids-MacBook-Pro solidity-contracts % npx hardhat verify --network mainnet 0x57E1a87603bD1960D734243f8b2f5133911E009D 0xCdF7028ceAB81fA0C6971208e83fa7872994beE5 0x1293a54e160D1cd7075487898d65266081A15458 0xbbD3C0C794F40c4f993B03F65343aCC6fcfCb2e2 0xE47c80e8c23f6B4A1aE41c34837a0599D5D16bb0 0x1CCA7E410eE41739792eA0A24e00349Dd247680e 0x10DE37cF84202A20cae61069C617B3Aa874aF8b4
An unexpected error occurred:

TypeError: customChains is not iterable
    at getEtherscanEndpoints (/Users/david/dev/t/solidity-contracts/node_modules/@nomiclabs/hardhat-etherscan/src/network/prober.ts:33:37)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Environment._runTaskDefinition (/Users/david/dev/t/solidity-contracts/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
    at async Environment.run (/Users/david/dev/t/solidity-contracts/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
    at async SimpleTaskDefinition.verifySubtask [as action] (/Users/david/dev/t/solidity-contracts/node_modules/@nomiclabs/hardhat-etherscan/src/index.ts:209:30)
    at async Environment._runTaskDefinition (/Users/david/dev/t/solidity-contracts/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
    at async Environment.run (/Users/david/dev/t/solidity-contracts/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
    at async Environment._runTaskDefinition (/Users/david/dev/t/solidity-contracts/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
    at async hardhatVerify (/Users/david/dev/t/solidity-contracts/node_modules/@openzeppelin/hardhat-upgrades/src/verify-proxy.ts:110:12)
    at async OverriddenTaskDefinition._action (/Users/david/dev/t/solidity-contracts/node_modules/@openzeppelin/hardhat-upgrades/src/index.ts:155:12)

Higher version (^3.1.0) reportedly causes problems with etherscan verification
on Mainnet (`TypeError: customChains is not iterable`). See commit bf90cd5.
@michalinacienciala
Copy link
Contributor Author

Thank goodness I never close my console tabs. Found it:

david@Davids-MacBook-Pro solidity-contracts % npx hardhat verify --network mainnet 0x57E1a87603bD1960D734243f8b2f5133911E009D 0xCdF7028ceAB81fA0C6971208e83fa7872994beE5 0x1293a54e160D1cd7075487898d65266081A15458 0xbbD3C0C794F40c4f993B03F65343aCC6fcfCb2e2 0xE47c80e8c23f6B4A1aE41c34837a0599D5D16bb0 0x1CCA7E410eE41739792eA0A24e00349Dd247680e 0x10DE37cF84202A20cae61069C617B3Aa874aF8b4
An unexpected error occurred:

TypeError: customChains is not iterable
    at getEtherscanEndpoints (/Users/david/dev/t/solidity-contracts/node_modules/@nomiclabs/hardhat-etherscan/src/network/prober.ts:33:37)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Environment._runTaskDefinition (/Users/david/dev/t/solidity-contracts/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
    at async Environment.run (/Users/david/dev/t/solidity-contracts/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
    at async SimpleTaskDefinition.verifySubtask [as action] (/Users/david/dev/t/solidity-contracts/node_modules/@nomiclabs/hardhat-etherscan/src/index.ts:209:30)
    at async Environment._runTaskDefinition (/Users/david/dev/t/solidity-contracts/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
    at async Environment.run (/Users/david/dev/t/solidity-contracts/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
    at async Environment._runTaskDefinition (/Users/david/dev/t/solidity-contracts/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
    at async hardhatVerify (/Users/david/dev/t/solidity-contracts/node_modules/@openzeppelin/hardhat-upgrades/src/verify-proxy.ts:110:12)
    at async OverriddenTaskDefinition._action (/Users/david/dev/t/solidity-contracts/node_modules/@openzeppelin/hardhat-upgrades/src/index.ts:155:12)

@cygnusv, I had a bit similar-sounding issue (TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))) before I upgraded hardhat-deploy to 0.11.15.
Just to be safe, I downgraded the @nomiclabs/hardhat-etherscan to 3.0.4.

@michalinacienciala michalinacienciala marked this pull request as draft September 20, 2022 10:17
await hre.ethers.provider.waitForTransaction(
timelock.transactionHash,
5,
300000
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the occasional need for this, but there's nothing inherent to TokenholderGovernor that requires an extra waiting time. It can happen to other deployments with some small probability. Can we instead add this to all Etherscan verification calls? Ideally, we can introduce it as part of a helper function.

@michalinacienciala
Copy link
Contributor Author

Before I do any further changes, I want to wait for the fix of the problem with failing unit tests which is introduced by upgrading hardhat-deploy dependency. PR for that: #126.

Without the change, the verification of contracts on Etherscan could sometimes
fail with error like this:
```
Verifying contract 0x... on Etherscan...
Nothing to compile
NomicLabsHardhatPluginError: Failed to send contract verification request.
Endpoint URL: https://api-goerli.etherscan.io/api
Reason: The Etherscan API responded that the address 0x... does not have
bytecode.
This can happen if the contract was recently deployed and this fact hasn't
propagated to the backend yet.
Try waiting for a minute before verifying your contract. If you are invoking
this from a script, try to wait for five confirmations of your contract
depiloyment transaction before running the verification subtask.
```
In PR #126 (#126)
we've upgraded the `hardhat-deploy` plugin to latest version (^0.11.15). As part
of this change, the way of storing Etherscan API key has changed - to be
different from how the key is stored for @nomiclabs/hardhat-etherscan plugin
use. When we merged those changes from `main` to the current feature branch, we
no longer had a correct format of the Etherscan API key config to use it with
the `@nomiclabs/hardhat-etherscan` plugin. As we don't want to verify contracts
using `hardhat-deploy` plugin anymore, we need to adjust the config to fit
`@nomiclabs/hardhat-etherscan`'s syntax.
@michalinacienciala
Copy link
Contributor Author

@michalinacienciala michalinacienciala marked this pull request as ready for review October 7, 2022 14:35
const { deployer } = await getNamedAccounts()

const T = await deployments.deploy("T", {
from: deployer,
log: true,
})

if (hre.network.tags.etherscan) {
await hre.ethers.provider.waitForTransaction(T.transactionHash, 5, 300000)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@michalinacienciala michalinacienciala Oct 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to use waitForConfirmations: 1 and waitForConfirmations: 5, but nome of the options was good:

The force-pushes seen below were a result of me going back to the original solution (i.e. using hre.ethers.provider.waitForTransaction).

@michalinacienciala michalinacienciala marked this pull request as draft October 10, 2022 06:56
@michalinacienciala michalinacienciala force-pushed the etherscan-verification branch 2 times, most recently from 2957914 to e565fbf Compare October 12, 2022 13:13
@michalinacienciala michalinacienciala marked this pull request as ready for review October 12, 2022 13:18
michalinacienciala added a commit to keep-network/coverage-pools that referenced this pull request Oct 18, 2023
The Görli testnet currently used by Threshold/Keep for development purposes is
planned to become deprecated with the end of year 2023. The testnet that was
created to replace it is called
[Holešky](https://github.com/eth-clients/holesky), however it will take some
time until it gets integrated with by some of the projects we rely on.
As a solution, we decided to switch first to another testnet that is currently
live - Sepolia. This testnet's EOL is planned for 2026, which gives us plenty of
time to move to Holešky before Sepolia gets deprecated.
Until Görli is not dead we want to support both testnets, which is what we did
in some of the projects already. In `coverage-pools` however we were missing
some Görli configuration. So for now, for consistency between projects, we've
added the missing part for Görli support and also added full support of Sepolia
testnet.
Some other changes:
- we've removed the `contracts-etherscan-verification` job from CI (it was
  needed when `hardhat-deploy` was used to verify contracts, but in
  threshold-network/solidity-contracts#125 we switched
  to using `@nomiclabs/hardhat-etherscan` plugin
- we've updated the versions of some of the actions used in our CI, as the
  previously set versions were running on `node14` which will be no longer
  supported by GH at some point in the future
michalinacienciala added a commit to keep-network/coverage-pools that referenced this pull request Oct 18, 2023
The Görli testnet currently used by Threshold/Keep for development purposes is
planned to become deprecated with the end of year 2023. The testnet that was
created to replace it is called
[Holešky](https://github.com/eth-clients/holesky), however it will take some
time until it gets integrated with by some of the projects we rely on.
As a solution, we decided to switch first to another testnet that is currently
live - Sepolia. This testnet's EOL is planned for 2026, which gives us plenty of
time to move to Holešky before Sepolia gets deprecated.
Until Görli is not dead we want to support both testnets, which is what we did
in some of the projects already. In `coverage-pools` however we were missing
some Görli configuration. So for now, for consistency between projects, we've
added the missing part for Görli support and also added full support of Sepolia
testnet.
Some other changes:
- we've removed the `contracts-etherscan-verification` job from CI (it was
  needed when `hardhat-deploy` was used to verify contracts, but in
  threshold-network/solidity-contracts#125 we switched
  to using `@nomiclabs/hardhat-etherscan` plugin
- we've updated the versions of some of the actions used in our CI, as the
  previously set versions were running on `node14` which will be no longer
  supported by GH at some point in the future
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants