Skip to content

Commit 7140c3a

Browse files
committed
update upgrade guide
1 parent 246d56e commit 7140c3a

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

docs/src/content/ignition/docs/guides/upgradeable-proxies.md

+31-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Using Hardhat Ignition with upgradeable proxies
1+
# Upgradeable proxies
22

33
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.
44

@@ -10,6 +10,30 @@ The finished code for this guide can be found in the [Hardhat Ignition monorepo]
1010

1111
:::
1212

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+
1337
## Getting to know our contracts
1438

1539
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
142166

143167
Next, we deploy our `Demo` contract. This will be the contract that we'll upgrade.
144168

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"`).
146170

147171
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.
148172

149173
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.
150174

151175
### Part 2: Interacting with our proxy
152176

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` inside this same file:
154178

155179
```js
156180
const demoModule = buildModule("DemoModule", (m) => {
157-
const { proxy, proxyAdmin } = m.useModule(upgradeModule);
181+
const { proxy, proxyAdmin } = m.useModule(proxyModule);
158182

159183
const demo = m.contractAt("Demo", proxy);
160184

@@ -278,6 +302,7 @@ Inside our `test` directory, we'll create a file called `ProxyDemo.js` (or `Prox
278302

279303
```typescript
280304
import { expect } from "chai";
305+
import { ignition, ethers } from "hardhat";
281306

282307
import ProxyModule from "../ignition/modules/ProxyModule";
283308
import UpgradeModule from "../ignition/modules/UpgradeModule";
@@ -297,7 +322,7 @@ describe("Demo Proxy", function () {
297322
it("Should have upgraded the proxy to DemoV2", async function () {
298323
const [, otherAccount] = await ethers.getSigners();
299324

300-
const { demo } = await ignition.deploy(ProxyModule);
325+
const { demo } = await ignition.deploy(UpgradeModule);
301326

302327
expect(await demo.connect(otherAccount).version()).to.equal("2.0.0");
303328
});
@@ -358,7 +383,7 @@ describe("Demo Proxy", function () {
358383

359384
::::
360385

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"`.
362387

363388
## Further reading
364389

0 commit comments

Comments
 (0)