Skip to content

Commit a8b7593

Browse files
authored
Etherscan V2 workaround (#2679)
* configure workaround for Etherscan V2 api * fix typo * fix endpoint configuration error * add verification examples to readme where deployed contracts have constructor parameters
1 parent 6c5c3a1 commit a8b7593

2 files changed

Lines changed: 54 additions & 9 deletions

File tree

contracts/README.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,14 +419,51 @@ Validator public key: 90db8ae56a9e741775ca37dd960606541306974d4a998ef6a6227c85a9
419419

420420
## Contract Verification
421421

422-
The Hardhat plug-in [@nomiclabs/hardhat-etherscan](https://www.npmjs.com/package/@nomiclabs/hardhat-etherscan) is used to verify contracts on Etherscan.
422+
The Hardhat plug-in [@nomiclabs/hardhat-verify](https://www.npmjs.com/package/@nomiclabs/hardhat-etherscan) is used to verify contracts on Etherscan. Etherscan has migrated to V2 api where all the chains use the same endpoint. Hardhat verify should be run with `--contract` parameter otherwise there is a significant slowdown while hardhat is gathering contract information.
423423

424424
There's an example
425425

426426
```
427427
npx hardhat --network mainnet verify --contract contracts/vault/VaultAdmin.sol:VaultAdmin 0x31a91336414d3B955E494E7d485a6B06b55FC8fB
428428
```
429429

430+
Example with constructor parameters passed as command params
431+
```
432+
yarn hardhat verify --network mainnet 0x0FC66355B681503eFeE7741BD848080d809FD6db --contract contracts/poolBooster/PoolBoosterFactoryMerkl.sol:PoolBoosterFactoryMerkl 0x856c4Efb76C1D1AE02e20CEB03A2A6a08b0b8dC3 0x4FF1b9D9ba8558F5EAfCec096318eA0d8b541971 0xAA8af8Db4B6a827B51786334d26349eb03569731 0x8BB4C975Ff3c250e0ceEA271728547f3802B36Fd
433+
```
434+
435+
Example with constructor parameters saved to file and file path passed to the command
436+
```
437+
echo "module.exports = [{
438+
platformAddress: \"0x0000000000000000000000000000000000000001\",
439+
vaultAddress: \"0xe75d77b1865ae93c7eaa3040b038d7aa7bc02f70\",
440+
}]" > flux-args.js
441+
npx hardhat --network mainnet verify --contract contracts/strategies/FluxStrategy.sol:FluxStrategy --constructor-args flux-args.js 0x57d49c28Cf9A0f65B1279a97eD01C3e49a5A173f
442+
```
443+
444+
445+
446+
`hardhat-deploy` package offers a secondary way to verify contracts, where contructor parameters don't need to be passed into the verification call. Since Etherscan has migrated to V2 api this approach is no longer working. `etherscan-verify` call uses `hardhat verify` under the hood.
447+
```
448+
npx hardhat etherscan-verify --network mainnet --api-url https://api.etherscan.io
449+
```
450+
451+
#### Addressing verification slowdowns
452+
453+
Profiling the `hardhat-verify` prooved that when the `hardhat verify` is ran without --contract parameter
454+
it can take up to 4-5 minutes to gather the necessary contract information.
455+
Use `--contract` e.g. `--contract contracts/vault/VaultAdmin.sol:VaultAdmin` to mitigate the issue.
456+
457+
#### Migration to full support of Etherscan V2 api
458+
459+
Migrating to Etherscan V2 has been attempted with no success.
460+
Resources:
461+
- migration guid by Etherscan: https://docs.etherscan.io/v2-migration
462+
- guide for Hardhat setup: https://docs.etherscan.io/contract-verification/verify-with-hardhat. (note upgrading @nomicfoundation/hardhat-verify to 2.0.14 didn't resolve the issue last time)
463+
- openzeppelin-upgrades claims to have solved the issue in 3.9.1 version of the package: https://github.com/OpenZeppelin/openzeppelin-upgrades/issues/1165 Not only does this not solve the verification issue, it is also a breaking change for our repo.
464+
465+
Good luck when attempting to solve this.
466+
430467
### Deployed contract code verification
431468

432469
To verify the deployed contract against the locally compiled contracts sol2uml from Nick Addison is convenient:

contracts/hardhat.config.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -415,35 +415,43 @@ module.exports = {
415415
etherscan: {
416416
apiKey: {
417417
mainnet: process.env.ETHERSCAN_API_KEY,
418-
arbitrumOne: process.env.ARBISCAN_API_KEY,
418+
arbitrumOne: process.env.ETHERSCAN_API_KEY,
419419
holesky: process.env.ETHERSCAN_API_KEY,
420-
base: process.env.BASESCAN_API_KEY,
421-
sonic: process.env.SONICSCAN_API_KEY,
422-
hoodi: process.env.HOODISCAN_API_KEY,
420+
base: process.env.ETHERSCAN_API_KEY,
421+
sonic: process.env.ETHERSCAN_API_KEY,
422+
hoodi: process.env.ETHERSCAN_API_KEY,
423423
plume: "empty", // this works for: npx hardhat verify...
424424
},
425425
customChains: [
426+
{
427+
network: "mainnet",
428+
chainId: 1,
429+
urls: {
430+
apiURL: "https://api.etherscan.io/v2/api?chainId=1",
431+
browserURL: "https://etherscan.io",
432+
},
433+
},
426434
{
427435
network: "holesky",
428436
chainId: 17000,
429437
urls: {
430-
apiURL: "https://api-holesky.etherscan.io/api",
438+
apiURL: "https://api.etherscan.io/v2/api?chainId=17000",
431439
browserURL: "https://holesky.etherscan.io",
432440
},
433441
},
434442
{
435443
network: "base",
436444
chainId: 8453,
437445
urls: {
438-
apiURL: "https://api.basescan.org/api",
446+
apiURL: "https://api.etherscan.io/v2/api?chainId=8453",
439447
browserURL: "https://basescan.org",
440448
},
441449
},
442450
{
443451
network: "sonic",
444452
chainId: 146,
445453
urls: {
446-
apiURL: "https://api.sonicscan.org/api",
454+
apiURL: "https://api.etherscan.io/v2/api?chainId=146",
447455
browserURL: "https://sonicscan.org",
448456
},
449457
},
@@ -459,7 +467,7 @@ module.exports = {
459467
network: "hoodi",
460468
chainId: 560048,
461469
urls: {
462-
apiURL: "https://hoodi.etherscan.io/api",
470+
apiURL: "https://api.etherscan.io/v2/api?chainId=560048",
463471
browserURL: "https://hoodi.etherscan.io",
464472
},
465473
},

0 commit comments

Comments
 (0)