From e21fb4066102e9842606acdb08275027f3596d86 Mon Sep 17 00:00:00 2001 From: Michael Bumann Date: Mon, 4 Jul 2022 20:00:53 +0200 Subject: [PATCH] Add an example script on how to upgrade a contract implementation --- README.md | 5 ++++- scripts/upgrade-example.js | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 scripts/upgrade-example.js diff --git a/README.md b/README.md index a8a738b..8ca0b37 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ To run these scripts use `hardhat run`. For example: `hardhat run scripts/list-c Some scripts are also defined as npm script, see package.json. -### repl.js +### repl/console Similar to cli.js but only provides a REPL with an initialized `kredits` instance. @@ -108,6 +108,9 @@ We use OpenZeppelin for an upgradeable contracts: [https://www.npmjs.com/package Refer to the OpenZeppelin README and `scripts/create-proxy.js` +For an upgrade example checkout `scripts/upgrade-example.js` + + ## Known Issues When resetting ganache Metamask might have an invalid transaction nonce and diff --git a/scripts/upgrade-example.js b/scripts/upgrade-example.js new file mode 100644 index 0000000..06f2bab --- /dev/null +++ b/scripts/upgrade-example.js @@ -0,0 +1,16 @@ +const { ethers, upgrades } = require("hardhat"); +const Kredits = require('../lib/kredits'); + +async function main() { + const network = await hre.ethers.provider.getNetwork(); + kredits = new Kredits(hre.ethers.provider, hre.ethers.provider.getSigner()); + await kredits.init(); + + const ContributorV2 = await ethers.getContractFactory("Contributor"); + const contributor = await upgrades.upgradeProxy(kredits.Contributor.address, ContributorV2); + console.log("Contributor upgraded"); + + console.log("DONE!"); +} + +main();