-
Notifications
You must be signed in to change notification settings - Fork 18
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
base: main
Are you sure you want to change the base?
Conversation
@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.
Workflow dry-runned here: https://github.com/threshold-network/solidity-contracts/actions/runs/3081781328/jobs/4981728262. |
FWIW, I've had issues with v3.1.0 in this project (see commit bf90cd5), so I had to pin 3.0.4. |
Thank goodness I never close my console tabs. Found it:
|
Higher version (^3.1.0) reportedly causes problems with etherscan verification on Mainnet (`TypeError: customChains is not iterable`). See commit bf90cd5.
@cygnusv, I had a bit similar-sounding issue ( |
await hre.ethers.provider.waitForTransaction( | ||
timelock.transactionHash, | ||
5, | ||
300000 |
There was a problem hiding this comment.
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.
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 |
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.
5203c81
to
c12c494
Compare
Workflow verified in run: https://github.com/threshold-network/solidity-contracts/actions/runs/3205279132/jobs/5237683036. |
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we try using waitForConfirmations
as we did in https://github.com/keep-network/keep-core/blob/4049dc0153c33c3c4cbb2e9a1808581bf76144fb/solidity/random-beacon/deploy/01_deploy_reimbursement_pool.ts#L15?
There was a problem hiding this comment.
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:
waitForConfirmations: 5
was causing hanging of the deploy function when executed on thehardhat
network (see waitConfirmations > 1 on hardhat network stalls deployment wighawag/hardhat-deploy#304)waitForConfirmations: 1
was not enough, the deploy ofTokenholderGovernor
was failing.
The force-pushes seen below were a result of me going back to the original solution (i.e. using hre.ethers.provider.waitForTransaction
).
2957914
to
e565fbf
Compare
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
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
@nomiclabs/hardhat-etherscan
exposes verification functions for Etherscan thatare recommended by the hardhat team.
See https://hardhat.org/hardhat-runner/plugins/nomiclabs-hardhat-etherscan
Previously we were using
etherscan-verify
fromhardhat-deploy
plugin, whichhad 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.