Skip to content

Commit acbda54

Browse files
authored
Merge pull request #4631 from NomicFoundation/docs/ignition-verify
Added a guide for verifying contracts with hardhat ignition
2 parents 9343122 + 34a113f commit acbda54

File tree

3 files changed

+176
-5
lines changed

3 files changed

+176
-5
lines changed

docs/src/content/ignition/docs/guides/_dirinfo.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ order:
77
- /error-handling
88
- /modifications
99
- /tests
10+
- /verify
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
# Verifying your deployment
2+
3+
Once your Ignition module is tested and ready, the next step is to deploy it to a live network and verify the source code of each of its contracts.
4+
5+
Verifying a contract means making its source code public, along with the compiler settings you used, which allows anyone to compile it and compare the generated bytecode with the one that is deployed on-chain. Doing this is extremely important in an open platform like Ethereum.
6+
7+
In this guide we'll explain how to do this with the [Etherscan](https://etherscan.io/) explorer.
8+
9+
## Getting an API key from Etherscan
10+
11+
The first thing you need is an API key from Etherscan. To get one, go to [their site](https://etherscan.io/login), sign in (or create an account if you don't have one) and open the "API Keys" tab. Then click the "Add" button and give a name to the API key you are creating (e.g. "Hardhat"). After that you'll see the newly created key in the list.
12+
13+
Open your Hardhat config and add the API key you just created:
14+
15+
::::tabsgroup{options=TypeScript,JavaScript}
16+
17+
:::tab{value=TypeScript}
18+
19+
```ts
20+
export default {
21+
// ...rest of the config...
22+
etherscan: {
23+
apiKey: "ABCDE12345ABCDE12345ABCDE123456789",
24+
},
25+
};
26+
```
27+
28+
:::
29+
30+
:::tab{value=JavaScript}
31+
32+
```js
33+
module.exports = {
34+
// ...rest of the config...
35+
etherscan: {
36+
apiKey: "ABCDE12345ABCDE12345ABCDE123456789",
37+
},
38+
};
39+
```
40+
41+
:::
42+
43+
::::
44+
45+
## Deploying and verifying on the Sepolia testnet
46+
47+
We are going to use the [Sepolia testnet](https://ethereum.org/en/developers/docs/networks/#sepolia) to deploy and verify our Ignition module, so you need to add this network in your Hardhat config. Here we are using [Alchemy](https://alchemy.com/) to connect to the network.
48+
49+
:::tip
50+
51+
For more information on `vars` and configuration variables, please see our [configuration variables guide](../../../hardhat-runner/docs/guides/configuration-variables.md).
52+
53+
:::
54+
55+
::::tabsgroup{options=TypeScript,JavaScript}
56+
57+
:::tab{value=TypeScript}
58+
59+
```ts
60+
// Go to https://alchemy.com, sign up, create a new App in
61+
// its dashboard, and set the Hardhat configuration variable
62+
// ALCHEMY_API_KEY to the key
63+
const ALCHEMY_API_KEY = vars.get("ALCHEMY_API_KEY");
64+
65+
// Replace this private key with your Sepolia test account private key
66+
// To export your private key from Coinbase Wallet, go to
67+
// Settings > Developer Settings > Show private key
68+
// To export your private key from Metamask, open Metamask and
69+
// go to Account Details > Export Private Key
70+
// Beware: NEVER put real Ether into testing accounts
71+
const SEPOLIA_PRIVATE_KEY = vars.get("SEPOLIA_PRIVATE_KEY");
72+
73+
export default {
74+
// ...rest of your config...
75+
networks: {
76+
sepolia: {
77+
url: `https://eth-sepolia.g.alchemy.com/v2/${ALCHEMY_API_KEY}`,
78+
accounts: [SEPOLIA_PRIVATE_KEY],
79+
},
80+
},
81+
};
82+
```
83+
84+
:::
85+
86+
:::tab{value=JavaScript}
87+
88+
```js
89+
// Go to https://alchemy.com, sign up, create a new App in
90+
// its dashboard, and set the Hardhat configuration variable
91+
// ALCHEMY_API_KEY to the key
92+
const ALCHEMY_API_KEY = vars.get("ALCHEMY_API_KEY");
93+
94+
// Replace this private key with your Sepolia test account private key
95+
// To export your private key from Coinbase Wallet, go to
96+
// Settings > Developer Settings > Show private key
97+
// To export your private key from Metamask, open Metamask and
98+
// go to Account Details > Export Private Key
99+
// Beware: NEVER put real Ether into testing accounts
100+
const SEPOLIA_PRIVATE_KEY = vars.get("SEPOLIA_PRIVATE_KEY");
101+
102+
module.exports = {
103+
// ...rest of your config...
104+
networks: {
105+
sepolia: {
106+
url: `https://eth-sepolia.g.alchemy.com/v2/${ALCHEMY_API_KEY}`,
107+
accounts: [SEPOLIA_PRIVATE_KEY],
108+
},
109+
},
110+
};
111+
```
112+
113+
:::
114+
115+
::::
116+
117+
To deploy on Sepolia you need to send some Sepolia ether to the address that's going to be making the deployment. You can get testnet ether from a faucet, a service that distributes testing-ETH for free. Here is one for Sepolia:
118+
119+
- [Alchemy Sepolia Faucet](https://sepoliafaucet.com/)
120+
121+
:::tip
122+
123+
This guide assumes you are using the contracts and Ignition module from the [quick start guide](/ignition/docs/getting-started#quick-start), but the steps are the same for any deployment.
124+
125+
:::
126+
127+
Now you are ready to deploy your module to the testnet, but first we are going to make the source code of our contract unique. The reason we need to do this is that the sample code from the quick start guide is already verified in Sepolia, so if you try to verify it you'll get an error. If you are using your own contracts, you can likely skip this step.
128+
129+
Open your contract and add a comment with something unique, like your GitHub's username. Keep in mind that whatever you include here will be, like the rest of the code, publicly available on Etherscan:
130+
131+
```solidity
132+
// Author: @janedoe
133+
contract Rocket {
134+
```
135+
136+
You can now run the deployment using the newly added Sepolia network:
137+
138+
::::tabsgroup{options="TypeScript,JavaScript"}
139+
140+
:::tab{value="TypeScript"}
141+
142+
```sh
143+
npx hardhat ignition deploy ignition/modules/Apollo.ts --network sepolia --verify
144+
```
145+
146+
:::
147+
148+
:::tab{value="JavaScript"}
149+
150+
```sh
151+
npx hardhat ignition deploy ignition/modules/Apollo.js --network sepolia --verify
152+
```
153+
154+
:::
155+
156+
::::
157+
158+
The `--verify` flag is optional, but it tells Hardhat Ignition to verify the contracts after a successful deployment.
159+
160+
If you have an existing deployment and want to verify it, you can also run the `verify` task directly by passing the deployment ID:
161+
162+
```sh
163+
npx hardhat ignition verify chain-11155111
164+
```
165+
166+
:::tip
167+
168+
If you get an error saying that the address does not have bytecode, it probably means that Etherscan has not indexed your contract yet. In that case, wait for a minute and then try again.
169+
170+
:::
171+
172+
After the task has successfully executed, for each deployed contract you'll see a link to its publicly verified code.
173+
174+
To learn more about verifying, read the [hardhat-verify](/hardhat-runner/plugins/nomicfoundation-hardhat-verify) documentation.

docs/temp/tabsConfig.json

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"TypeScript/JavaScript": "TypeScript",
3-
"npm 7+/npm 6/yarn": "npm 7+",
4-
"Infura/Alchemy": "Infura"
5-
}
1+
{"TypeScript/JavaScript":"TypeScript","Alchemy/Infura":"Alchemy"}

0 commit comments

Comments
 (0)