@@ -8,77 +8,77 @@ To get started, we’ll uninstall the `hardhat-deploy` plugin and install the Ha
8
8
9
9
1 . Remove the ` hardhat-deploy ` packages from your project:
10
10
11
- :::: tabsgroup { options =" npm,yarn " }
11
+ :::: tabsgroup { options =" npm,yarn " }
12
12
13
- ::: tab { value =" npm " }
13
+ ::: tab { value =" npm " }
14
14
15
- ``` sh
16
- npm uninstall hardhat-deploy hardhat-deploy-ethers
17
- ```
15
+ ``` sh
16
+ npm uninstall hardhat-deploy hardhat-deploy-ethers
17
+ ```
18
18
19
- :::
19
+ :::
20
20
21
- ::: tab { value =yarn }
21
+ ::: tab { value =yarn }
22
22
23
- ``` sh
24
- yarn remove hardhat-deploy hardhat-deploy-ethers
25
- ```
23
+ ``` sh
24
+ yarn remove hardhat-deploy hardhat-deploy-ethers
25
+ ```
26
26
27
- :::
27
+ :::
28
28
29
- ::::
29
+ ::::
30
30
31
31
2 . Install the Hardhat Ignition package and ` hardhat-network-helpers ` to provide additional testing support as a replacement for ` hardhat-deploy ` functionality like EVM snapshots:
32
32
33
- :::: tabsgroup { options =" npm,yarn " }
33
+ :::: tabsgroup { options =" npm,yarn " }
34
34
35
- ::: tab { value =" npm " }
35
+ ::: tab { value =" npm " }
36
36
37
- ``` sh
38
- npm install --save-dev @nomicfoundation/hardhat-ignition-ethers @nomicfoundation/hardhat-network-helpers
39
- ```
37
+ ``` sh
38
+ npm install --save-dev @nomicfoundation/hardhat-ignition-ethers @nomicfoundation/hardhat-network-helpers
39
+ ```
40
40
41
- :::
41
+ :::
42
42
43
- ::: tab { value =yarn }
43
+ ::: tab { value =yarn }
44
44
45
- ``` sh
46
- yarn add --dev @nomicfoundation/hardhat-ignition-ethers @nomicfoundation/hardhat-network-helpers
47
- ```
45
+ ``` sh
46
+ yarn add --dev @nomicfoundation/hardhat-ignition-ethers @nomicfoundation/hardhat-network-helpers
47
+ ```
48
48
49
- :::
49
+ :::
50
50
51
- ::::
51
+ ::::
52
52
53
53
3 . Update the project’s ` hardhat.config ` file to remove ` hardhat-deploy ` and ` hardhat-deploy-ethers ` and instead import Hardhat Ignition:
54
54
55
- :::: tabsgroup { options =" typescript,javascript " }
55
+ :::: tabsgroup { options =" typescript,javascript " }
56
56
57
- ::: tab { value =" typescript " }
57
+ ::: tab { value =" typescript " }
58
58
59
- ``` git
60
- - import "hardhat-deploy";
61
- - import "hardhat-deploy-ethers";
62
- + import "@nomicfoundation/hardhat-ignition-ethers";
63
- ```
59
+ ``` git
60
+ - import "hardhat-deploy";
61
+ - import "hardhat-deploy-ethers";
62
+ + import "@nomicfoundation/hardhat-ignition-ethers";
63
+ ```
64
64
65
- :::
65
+ :::
66
66
67
- ::: tab { value =javascript }
67
+ ::: tab { value =javascript }
68
68
69
- ``` git
70
- - require("hardhat-deploy");
71
- - require("hardhat-deploy-ethers");
72
- + require("@nomicfoundation/hardhat-ignition-ethers");
73
- ```
69
+ ``` git
70
+ - require("hardhat-deploy");
71
+ - require("hardhat-deploy-ethers");
72
+ + require("@nomicfoundation/hardhat-ignition-ethers");
73
+ ```
74
74
75
- :::
75
+ :::
76
76
77
- ::::
77
+ ::::
78
78
79
79
## Convert deployment scripts to Ignition Modules
80
80
81
- ` hardhat-deploy ` represents contract deployments as JavaScript or TypeScript files under the ` ./deploy/ ` folder. Hardhat Ignition follows a similar pattern with deployments encapsulated as modules; these are JS/TS files stored under the ` ./ignition/modules directory ` . Each ` hardhat-deploy ` deploy file will be converted or merged into a Hardhat Ignition module.
81
+ ` hardhat-deploy ` represents contract deployments as JavaScript or TypeScript files under the ` ./deploy/ ` folder. Hardhat Ignition follows a similar pattern with deployments encapsulated as modules; these are JS/TS files stored under the ` ./ignition/modules ` directory. Each ` hardhat-deploy ` deploy file will be converted or merged into a Hardhat Ignition module.
82
82
83
83
Let’s first create the required folder structure under the root of your project:
84
84
@@ -97,13 +97,16 @@ contract Token {
97
97
uint256 public totalSupply = 1000000;
98
98
address public owner;
99
99
mapping(address => uint256) balances;
100
+
100
101
constructor(address _owner) {
101
102
balances[_owner] = totalSupply;
102
103
owner = _owner;
103
104
}
105
+
104
106
function balanceOf(address account) external view returns (uint256) {
105
107
return balances[account];
106
108
}
109
+
107
110
function transfer(address to, uint256 amount) external {
108
111
require(balances[msg.sender] >= amount, "Not enough tokens");
109
112
balances[msg.sender] -= amount;
@@ -123,9 +126,9 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
123
126
const { deployments, getNamedAccounts } = hre ;
124
127
const { deploy } = deployments ;
125
128
/*
126
- The deploy function uses the hardhat-deploy named accounts feature
127
- to set the deployment's `from` and `args` parameters.
128
- */
129
+ The deploy function uses the hardhat-deploy named accounts feature
130
+ to set the deployment's `from` and `args` parameters.
131
+ */
129
132
const { deployer, tokenOwner } = await getNamedAccounts ();
130
133
await deploy (" Token" , {
131
134
from: deployer ,
@@ -152,29 +155,29 @@ import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
152
155
For instance, you can deploy contracts via `m.contract()`.
153
156
*/
154
157
export default buildModule (" TokenModule" , (m ) => {
155
- /*
156
- Instead of named accounts, you get access to the configured accounts
157
- through the `getAccount()` method.
158
- */
158
+ /*
159
+ Instead of named accounts, you get access to the configured accounts
160
+ through the `getAccount()` method.
161
+ */
159
162
const deployer = m .getAccount (0 );
160
163
const tokenOwner = m .getAccount (1 );
161
164
162
165
/*
163
- Deploy `Token` by calling `contract()` with the constructor arguments
164
- as the second argument. The account to use for the deployment transaction
165
- is set through `from` in the third argument, which is an options object.
166
- */
166
+ Deploy `Token` by calling `contract()` with the constructor arguments
167
+ as the second argument. The account to use for the deployment transaction
168
+ is set through `from` in the third argument, which is an options object.
169
+ */
167
170
const token = m .contract (" Token" , [tokenOwner ], {
168
171
from: deployer ,
169
172
});
170
173
171
174
/*
172
- The call to `m.contract()` returns a future that can be used in other `m.contract()`
173
- calls (e.g. as a constructor argument, where the future will resolve to the
174
- deployed address), but it can also be returned from the module. Contract
175
- futures that are returned from the module can be leveraged in Hardhat tests
176
- and scripts, as will be shown later.
177
- */
175
+ The call to `m.contract()` returns a future that can be used in other `m.contract()`
176
+ calls (e.g. as a constructor argument, where the future will resolve to the
177
+ deployed address), but it can also be returned from the module. Contract
178
+ futures that are returned from the module can be leveraged in Hardhat tests
179
+ and scripts, as will be shown later.
180
+ */
178
181
return { token };
179
182
});
180
183
```
@@ -193,29 +196,29 @@ const { buildModule } = require("@nomicfoundation/hardhat-ignition/modules");
193
196
For instance, you can deploy contracts via `m.contract()`.
194
197
*/
195
198
module .exports = buildModule (" TokenModule" , (m ) => {
196
- /*
197
- Instead of named accounts, you get access to the configured accounts
198
- through the `getAccount()` method.
199
- */
199
+ /*
200
+ Instead of named accounts, you get access to the configured accounts
201
+ through the `getAccount()` method.
202
+ */
200
203
const deployer = m .getAccount (0 );
201
204
const tokenOwner = m .getAccount (1 );
202
205
203
206
/*
204
- Deploy `Token` by calling `contract()` with the constructor arguments
205
- as the second argument. The account to use for the deployment transaction
206
- is set through `from` in the third argument, which is an options object.
207
- */
207
+ Deploy `Token` by calling `contract()` with the constructor arguments
208
+ as the second argument. The account to use for the deployment transaction
209
+ is set through `from` in the third argument, which is an options object.
210
+ */
208
211
const token = m .contract (" Token" , [tokenOwner], {
209
212
from: deployer,
210
213
});
211
214
212
215
/*
213
- The call to `m.contract()` returns a future that can be used in other `m.contract()`
214
- calls (e.g. as a constructor argument, where the future will resolve to the
215
- deployed address), but it can also be returned from the module. Contract
216
- futures that are returned from the module can be leveraged in Hardhat tests
217
- and scripts, as will be shown later.
218
- */
216
+ The call to `m.contract()` returns a future that can be used in other `m.contract()`
217
+ calls (e.g. as a constructor argument, where the future will resolve to the
218
+ deployed address), but it can also be returned from the module. Contract
219
+ futures that are returned from the module can be leveraged in Hardhat tests
220
+ and scripts, as will be shown later.
221
+ */
219
222
return { token };
220
223
});
221
224
```
0 commit comments