Skip to content

Commit fb3fd34

Browse files
authored
Merge pull request #3867 from schaable/hardhat-etherscan-rewrite
Hardhat etherscan rewrite
2 parents e584429 + 3e9144e commit fb3fd34

File tree

124 files changed

+5401
-5114
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+5401
-5114
lines changed

.github/workflows/hardhat-etherscan-ci.yml .github/workflows/hardhat-verify-ci.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
1-
name: hardhat-etherscan CI
1+
name: hardhat-verify CI
22

33
on:
44
push:
55
branches: [$default-branch]
66
paths:
7-
- "packages/hardhat-etherscan/**"
7+
- "packages/hardhat-verify/**"
88
- "packages/hardhat-core/**"
99
- "packages/hardhat-common/**"
1010
- "config/**"
1111
pull_request:
1212
branches:
1313
- "**"
1414
paths:
15-
- "packages/hardhat-etherscan/**"
15+
- "packages/hardhat-verify/**"
1616
- "packages/hardhat-core/**"
1717
- "packages/hardhat-common/**"
1818
- "config/**"
1919

2020
defaults:
2121
run:
22-
working-directory: packages/hardhat-etherscan
22+
working-directory: packages/hardhat-verify
2323

2424
concurrency:
2525
group: ${{github.workflow}}-${{github.ref}}
2626
cancel-in-progress: true
2727

2828
jobs:
2929
test_on_windows:
30-
name: Test hardhat-etherscan on Windows with Node 14
30+
name: Test hardhat-verify on Windows with Node 14
3131
runs-on: windows-latest
3232
steps:
3333
- uses: actions/checkout@v2
@@ -43,7 +43,7 @@ jobs:
4343
run: yarn test
4444

4545
test_on_macos:
46-
name: Test hardhat-etherscan on MacOS with Node 14
46+
name: Test hardhat-verify on MacOS with Node 14
4747
runs-on: macos-latest
4848
# disable until actions/virtual-environments#4896 is fixed
4949
if: ${{ false }}
@@ -61,7 +61,7 @@ jobs:
6161
run: yarn test
6262

6363
test_on_linux:
64-
name: Test hardhat-etherscan on Ubuntu with Node ${{ matrix.node }}
64+
name: Test hardhat-verify on Ubuntu with Node ${{ matrix.node }}
6565
runs-on: ubuntu-latest
6666
strategy:
6767
matrix:

docs/redirects.config.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ const customRedirects = [
6363
},
6464
{
6565
source: "/verify-custom-networks",
66-
destination: "/plugins/nomiclabs-hardhat-etherscan#adding-support-for-other-networks",
66+
destination: "/plugins/nomicfoundation-hardhat-verify#adding-support-for-other-networks",
6767
permanent: false
6868
},
6969
{
7070
source: "/verify-multiple-networks",
71-
destination: "plugins/nomiclabs-hardhat-etherscan.html#multiple-api-keys-and-alternative-block-explorers",
71+
destination: "plugins/nomicfoundation-hardhat-verify.html#multiple-api-keys-and-alternative-block-explorers",
7272
permanent: false
7373
},
7474
{
@@ -261,6 +261,11 @@ const customRedirects = [
261261
destination: "/hardhat-network-helpers/docs/:slug",
262262
permanent: false
263263
},
264+
{
265+
source: "/hardhat-runner/plugins/nomiclabs-hardhat-etherscan",
266+
destination: "/hardhat-runner/plugins/nomicfoundation-hardhat-verify",
267+
permanent: false
268+
},
264269
...loadErrorRedirects()
265270
];
266271

docs/src/components/Navigation.mocks.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@
162162
"href": "/plugins/nomiclabs-hardhat-waffle"
163163
},
164164
{
165-
"label": "@nomiclabs/hardhat-etherscan",
166-
"href": "/plugins/nomiclabs-hardhat-etherscan"
165+
"label": "@nomicfoundation/hardhat-verify",
166+
"href": "/plugins/nomicfoundation-hardhat-verify"
167167
},
168168
{
169169
"label": "@nomiclabs/hardhat-web3",

docs/src/content/hardhat-runner/docs/guides/verifying.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,4 @@ If you get an error saying that the address does not have bytecode, it probably
155155

156156
After the task is successfully executed, you'll see a link to the publicly verified code of your contract.
157157

158-
To learn more about verifying, read the [hardhat-etherscan](/hardhat-runner/plugins/nomiclabs-hardhat-etherscan) documentation.
158+
To learn more about verifying, read the [hardhat-verify](/hardhat-runner/plugins/nomicfoundation-hardhat-verify) documentation.

docs/src/content/hardhat-runner/plugins/_dirinfo.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ order:
44
- "@nomicfoundation/hardhat-toolbox"
55
- "@nomicfoundation/hardhat-chai-matchers"
66
- "@nomiclabs/hardhat-ethers"
7-
- "@nomiclabs/hardhat-etherscan"
7+
- "@nomicfoundation/hardhat-verify"
88
- "@nomicfoundation/hardhat-foundry"
99
- "@nomiclabs/hardhat-vyper"
1010
- "@nomiclabs/hardhat-solhint"

docs/src/content/hardhat-runner/plugins/plugins.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -798,10 +798,10 @@ const officialPlugins: IPlugin[] = [
798798
tags: ["Ethers.js", "Testing", "Tasks", "Scripts"],
799799
},
800800
{
801-
name: "@nomiclabs/hardhat-etherscan",
801+
name: "@nomicfoundation/hardhat-verify",
802802
author: "Nomic Foundation",
803803
authorUrl: "https://twitter.com/NomicFoundation",
804-
description: "Automatically verify contracts on Etherscan",
804+
description: "Automatically verify contracts",
805805
tags: ["Etherscan", "Verification"],
806806
},
807807
{

package.json

+11-5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@
44
"author": "Nomic Labs LLC",
55
"license": "SEE LICENSE IN EACH PACKAGE'S LICENSE FILE",
66
"private": true,
7-
"workspaces": [
8-
"packages/*"
9-
],
7+
"workspaces": {
8+
"packages": [
9+
"packages/*"
10+
],
11+
"nohoist": [
12+
"**/find-up",
13+
"**/find-up/**"
14+
]
15+
},
1016
"devDependencies": {
1117
"@changesets/cli": "^2.16.0",
1218
"prettier": "2.4.1",
@@ -15,8 +21,8 @@
1521
"wsrun": "^5.2.2"
1622
},
1723
"scripts": {
18-
"build": "tsc --build packages/hardhat-core packages/hardhat-ethers packages/hardhat-etherscan packages/hardhat-solhint packages/hardhat-solpp packages/hardhat-truffle4 packages/hardhat-truffle5 packages/hardhat-vyper packages/hardhat-web3 packages/hardhat-web3-legacy packages/hardhat-chai-matchers packages/hardhat-network-helpers packages/hardhat-toolbox packages/hardhat-foundry",
19-
"watch": "tsc --build --watch packages/hardhat-core/src packages/hardhat-ethers packages/hardhat-etherscan packages/hardhat-solhint packages/hardhat-solpp packages/hardhat-truffle4 packages/hardhat-truffle5 packages/hardhat-vyper packages/hardhat-web3 packages/hardhat-web3-legacy packages/hardhat-chai-matchers packages/hardhat-network-helpers packages/hardhat-toolbox packages/hardhat-foundry",
24+
"build": "tsc --build packages/hardhat-core packages/hardhat-ethers packages/hardhat-verify packages/hardhat-solhint packages/hardhat-solpp packages/hardhat-truffle4 packages/hardhat-truffle5 packages/hardhat-vyper packages/hardhat-web3 packages/hardhat-web3-legacy packages/hardhat-chai-matchers packages/hardhat-network-helpers packages/hardhat-toolbox packages/hardhat-foundry",
25+
"watch": "tsc --build --watch packages/hardhat-core/src packages/hardhat-ethers packages/hardhat-verify packages/hardhat-solhint packages/hardhat-solpp packages/hardhat-truffle4 packages/hardhat-truffle5 packages/hardhat-vyper packages/hardhat-web3 packages/hardhat-web3-legacy packages/hardhat-chai-matchers packages/hardhat-network-helpers packages/hardhat-toolbox packages/hardhat-foundry",
2026
"clean": "wsrun --exclude-missing clean",
2127
"test": "node scripts/run-tests.js",
2228
"lint": "wsrun --exclude-missing --stages lint && yarn prettier --check",

packages/hardhat-etherscan/DEVELOPING.md

-10
This file was deleted.

packages/hardhat-etherscan/README.md

+6-210
Original file line numberDiff line numberDiff line change
@@ -2,216 +2,12 @@
22

33
# hardhat-etherscan
44

5-
[Hardhat](https://hardhat.org) plugin for integration with [Etherscan](https://etherscan.io)'s contract verification service.
5+
The `@nomiclabs/hardhat-etherscan` plugin is deprecated in favor of our new [`@nomicfoundation/hardhat-verify`](/packages/hardhat-verify) plugin.
66

7-
## What
7+
## Migrating to `hardhat-verify`
88

9-
This plugin helps you verify the source code for your Solidity contracts on [Etherscan](https://etherscan.io).
9+
`hardhat-verify` is a drop-in replacement of `hardhat-etherscan`. To migrate to it:
1010

11-
It's smart and it tries to do as much as possible to facilitate the process:
12-
13-
- Just provide the deployment address and constructor arguments, and the plugin will detect locally which contract to verify.
14-
- If your contract uses Solidity libraries, the plugin will detect them and deal with them automatically. You don't need to do anything about them.
15-
- A simulation of the verification process will run locally, allowing the plugin to detect and communicate any mistakes during the process.
16-
- Once the simulation is successful the contract will be verified using the Etherscan API.
17-
18-
## Installation
19-
20-
```bash
21-
npm install --save-dev @nomiclabs/hardhat-etherscan
22-
```
23-
24-
And add the following statement to your `hardhat.config.js`:
25-
26-
```js
27-
require("@nomiclabs/hardhat-etherscan");
28-
```
29-
30-
Or, if you are using TypeScript, add this to your `hardhat.config.ts`:
31-
32-
```js
33-
import "@nomiclabs/hardhat-etherscan";
34-
```
35-
36-
## Tasks
37-
38-
This plugin provides the `verify` task, which allows you to verify contracts through Etherscan's service.
39-
40-
## Environment extensions
41-
42-
This plugin does not extend the environment.
43-
44-
## Usage
45-
46-
You need to add the following Etherscan config to your `hardhat.config.js` file:
47-
48-
```js
49-
module.exports = {
50-
networks: {
51-
mainnet: { ... }
52-
},
53-
etherscan: {
54-
// Your API key for Etherscan
55-
// Obtain one at https://etherscan.io/
56-
apiKey: "YOUR_ETHERSCAN_API_KEY"
57-
}
58-
};
59-
```
60-
61-
Alternatively you can specify more than one block explorer API key, by passing an object under the `apiKey` property, see [`Multiple API keys and alternative block explorers`](#multiple-api-keys-and-alternative-block-explorers).
62-
63-
Lastly, run the `verify` task, passing the address of the contract, the network where it's deployed, and the constructor arguments that were used to deploy it (if any):
64-
65-
```bash
66-
npx hardhat verify --network mainnet DEPLOYED_CONTRACT_ADDRESS "Constructor argument 1"
67-
```
68-
69-
### Complex arguments
70-
71-
When the constructor has a complex argument list, you'll need to write a javascript module that exports the argument list. The expected format is the same as a constructor list for an [ethers contract](https://docs.ethers.io/v5/api/contract/). For example, if you have a contract like this:
72-
73-
```solidity
74-
struct Point {
75-
uint x;
76-
uint y;
77-
}
78-
79-
contract Foo {
80-
constructor (uint x, string s, Point memory point, bytes b) { ... }
81-
}
82-
```
83-
84-
then you can use an `arguments.js` file like this:
85-
86-
```js
87-
module.exports = [
88-
50,
89-
"a string argument",
90-
{
91-
x: 10,
92-
y: 5,
93-
},
94-
// bytes have to be 0x-prefixed
95-
"0xabcdef",
96-
];
97-
```
98-
99-
Where the third argument represents the value for the `point` parameter.
100-
101-
The module can then be loaded by the `verify` task when invoked like this:
102-
103-
```bash
104-
npx hardhat verify --constructor-args arguments.js DEPLOYED_CONTRACT_ADDRESS
105-
```
106-
107-
### Libraries with undetectable addresses
108-
109-
Some library addresses are undetectable. If your contract uses a library only in the constructor, then its address cannot be found in the deployed bytecode.
110-
111-
To supply these missing addresses, you can create a javascript module that exports a library dictionary and pass it through the `--libraries` parameter:
112-
113-
```bash
114-
hardhat verify --libraries libraries.js OTHER_ARGS
115-
```
116-
117-
where `libraries.js` looks like this:
118-
119-
```js
120-
module.exports = {
121-
SomeLibrary: "0x...",
122-
};
123-
```
124-
125-
### Multiple API keys and alternative block explorers
126-
127-
If your project targets multiple EVM-compatible networks that have different explorers, you'll need to set multiple API keys.
128-
129-
To configure the API keys for the chains you are using, provide an object under `etherscan/apiKey` with the identifier of each chain as the key. **This is not necessarily the same name that you are using to define the network**. For example, if you are going to verify contracts in Ethereum mainnet, Optimism and Arbitrum, your config would look like this:
130-
131-
```js
132-
module.exports = {
133-
networks: {
134-
mainnet: { ... },
135-
testnet: { ... }
136-
},
137-
etherscan: {
138-
apiKey: {
139-
mainnet: "YOUR_ETHERSCAN_API_KEY",
140-
optimisticEthereum: "YOUR_OPTIMISTIC_ETHERSCAN_API_KEY",
141-
arbitrumOne: "YOUR_ARBISCAN_API_KEY",
142-
}
143-
}
144-
};
145-
```
146-
147-
To see the full list of supported networks, run `npx hardhat verify --list-networks`. The identifiers shown there are the ones that should be used as keys in the `apiKey` object.
148-
149-
### Adding support for other networks
150-
151-
If the chain you are using is not in the list, you can manually add the necessary information to verify your contracts on it. For this you need three things: the chain id of the network, the URL of the verification endpoint, and the URL of the explorer.
152-
153-
For example, if Goerli wasn't supported, you could add it like this:
154-
155-
```
156-
etherscan: {
157-
apiKey: {
158-
goerli: "<goerli-api-key>"
159-
},
160-
customChains: [
161-
{
162-
network: "goerli",
163-
chainId: 5,
164-
urls: {
165-
apiURL: "https://api-goerli.etherscan.io/api",
166-
browserURL: "https://goerli.etherscan.io"
167-
}
168-
}
169-
]
170-
}
171-
```
172-
173-
Keep in mind that the name you are giving to the network in `customChains` is the same one that has to be used in the `apiKey` object.
174-
175-
To see which custom chains are supported, run `npx hardhat verify --list-networks`.
176-
177-
### Using programmatically
178-
179-
To call the verification task from within a Hardhat task or script, use the `"verify:verify"` subtask. Assuming the same contract as [above](#complex-arguments), you can run the subtask like this:
180-
181-
```js
182-
await hre.run("verify:verify", {
183-
address: contractAddress,
184-
constructorArguments: [
185-
50,
186-
"a string argument",
187-
{
188-
x: 10,
189-
y: 5,
190-
},
191-
"0xabcdef",
192-
],
193-
});
194-
```
195-
196-
If the verification is not successful, an error will be thrown.
197-
198-
#### Providing libraries from a script or task
199-
200-
If your contract has libraries with undetectable addresses, you may pass the libraries parameter with a dictionary specifying them:
201-
202-
```js
203-
hre.run("verify:verify", {
204-
// other args
205-
libraries: {
206-
SomeLibrary: "0x...",
207-
}
208-
}
209-
```
210-
211-
## How it works
212-
213-
The plugin works by fetching the bytecode in the given address and using it to check which contract in your project corresponds to it. Besides that, some sanity checks are performed locally to make sure that the verification won't fail.
214-
215-
## Known limitations
216-
217-
- Adding, removing, moving or renaming new contracts to the hardhat project or reorganizing the directory structure of contracts after deployment may alter the resulting bytecode in some solc versions. See this [Solidity issue](https://github.com/ethereum/solidity/issues/9573) for further information.
11+
1. Uninstall the `@nomiclabs/hardhat-etherscan` package
12+
2. Install the `@nomicfoundation/hardhat-verify` package
13+
3. Update your Hardhat config to import `@nomicfoundation/hardhat-verify` instead of `@nomiclabs/hardhat-etherscan`

0 commit comments

Comments
 (0)