You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/src/content/ignition/docs/guides/upgradeable-proxies.md
+31-6
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
# Using Hardhat Ignition with upgradeable proxies
1
+
# Upgradeable proxies
2
2
3
3
When developing smart contracts, you may decide to use an upgradeable proxy pattern to allow for future upgrades to your contracts. This guide will explain how to create Ignition modules to deploy and interact with your upgradeable proxy contracts.
4
4
@@ -10,6 +10,30 @@ The finished code for this guide can be found in the [Hardhat Ignition monorepo]
10
10
11
11
:::
12
12
13
+
## Installation
14
+
15
+
Before we get started, make sure you have the OpenZeppelin Contracts library installed in your project. You can install it using npm or yarn:
16
+
17
+
::::tabsgroup{options="npm,yarn"}
18
+
19
+
:::tab{value="npm"}
20
+
21
+
```sh
22
+
npm install @openzeppelin/contracts
23
+
```
24
+
25
+
:::
26
+
27
+
:::tab{value=yarn}
28
+
29
+
```sh
30
+
yarn add @openzeppelin/contracts
31
+
```
32
+
33
+
:::
34
+
35
+
::::
36
+
13
37
## Getting to know our contracts
14
38
15
39
Before we start writing our Ignition modules, let's take a look at the contracts we'll be deploying and interacting with.
@@ -142,19 +166,19 @@ First, we're getting our account that will own the ProxyAdmin contract. This acc
142
166
143
167
Next, we deploy our `Demo` contract. This will be the contract that we'll upgrade.
144
168
145
-
Then, we deploy our `TransparentUpgradeableProxy` contract. This contract will be deployed with the `Demo` contract as its implementation, and the `proxyAdminOwner` account as its owner. The third argument is the initialization code, which we'll leave blank for now by setting to an empty hex string (`"0x"`).
169
+
Then we deploy our `TransparentUpgradeableProxy` contract. This contract will be deployed with the `Demo` contract as its implementation, and the `proxyAdminOwner` account as its owner. The third argument is the initialization code, which we'll leave blank for now by setting to an empty hex string (`"0x"`).
146
170
147
171
When we deploy the proxy, it will automatically create a new `ProxyAdmin` contract within its constructor. We'll need to get the address of this contract so that we can interact with it later. To do this, we'll use the `m.readEventArgument(...)` method to read the `newAdmin` argument from the `AdminChanged` event that is emitted when the proxy is deployed.
148
172
149
173
Finally, we'll use the `m.contractAt(...)` method to tell Ignition to use the `ProxyAdmin` ABI for the contract at the address we just retrieved. This will allow us to interact with the `ProxyAdmin` contract when we upgrade our proxy.
150
174
151
175
### Part 2: Interacting with our proxy
152
176
153
-
Now that we have our proxy deployed, we're ready to interact with it. To do this, we'll create a new module called `DemoModule`:
177
+
Now that we have a module for deploying our proxy, we're ready to interact with it. To do this, we'll create a new module called `DemoModule`:
@@ -358,7 +383,7 @@ describe("Demo Proxy", function () {
358
383
359
384
::::
360
385
361
-
Here we use Hardhat Ignition to deploy our imported modules. First, we deploy our base `ProxyModule` that returns the first version of our `Demo` contract and test it to ensure the proxy worked and retrieves the appropriate version string. Then, we deploy our `UpgradeModule` that returns the second version of our `Demo` contract and test it to ensure the proxy now returns the updated version string. We also test that our initialization function was called and set the `name` state variable to `"Example Name"`.
386
+
Here we use Hardhat Ignition to deploy our imported modules. First, we deploy our base `ProxyModule` that returns the first version of our `Demo` contract and tests it to ensure the proxy worked and retrieves the appropriate version string. Then, we deploy our `UpgradeModule` that returns an upgraded version of our `Demo` contract and tests it to ensure the proxy returns the updated version string. We also test that our initialization function was called, setting the `name` state variable to `"Example Name"`.
0 commit comments