Git Product home page Git Product logo

hardhat-oz-for-upgrades-example's Introduction

hardhat-oz-upgrades-example

An example of hardhat contracts upgrades using OpenZeppelin

Getting Started ๐Ÿš€

Pre-requisites ๐Ÿ“‹

You need to have installed nodejs

See Hardhat setup enviroment tutorial

Installation ๐Ÿ”ง

First you need to clone this repository

git clone https://github.com/rafius97/hardhat-oz-upgrades-example/

Make sure you are in the right folder

cd hardhat-oz-upgrades-example/

Next, you must install the dependencies

yarn

Compiling ๐Ÿ—ƒ๏ธ

yarn compile

Running tests โš™๏ธ

In order to test using a mainnet fork you must set ALCHEMY_MAIN_API_KEY in your .env file

yarn test

Usage ๐Ÿ•น๏ธ

Case #1: Update the deployed contract

Imagine your using a testnet and constantly your making some changes to a deployed contract. In that case you can use:

yarn deploy-upgrade:rinkeby

In the example, rinkeby network it's used.

You need to make sure in the 3_deploy_upgrade.js file the contract factory has to be the same that your making the changes. For example:

const contract = await ethers.getContractFactory("Contract");

So, instead of create another contract file, just update the same contract your working with.

This is so useful when you are in the development phase, no need to redeploy the contract again.

Case #2: Upgrade the contract

Imagine you already deployed a contract in a mainnet and you need to make some changes to it:

yarn deploy-upgrade:rinkeby

In the example, rinkeby network it's used.

You need to make sure in the 3_deploy_upgrade.js file the contract factory has to be the contract file upgraded, usually version is added in the contract name. For example:

const contract = await ethers.getContractFactory("ContractV2");

This is so useful when you already have a contract deployed in the mainnet.

Remember always test before deploy

Extra: Verify the contract on Etherscan

Verify an upgradeable contract now it's easy using Hardhat, I make a task to handle that, and use the @nomiclabs/hardhat-etherscan plugin for Hardhat:

yarn verify-contract:rinkeby --address "0x00..."

Note #1: Make sure you set ETHERSCAN_API_KEY in your .env file

Note #2: Make sure that the contract address not to be the proxy contract address

Built with ๐Ÿ› ๏ธ

Author โœ’๏ธ

License ๐Ÿ“„

This project is under the MIT License - look up the file LICENSE.md for more details.

hardhat-oz-for-upgrades-example's People

Contributors

rafael-ab avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.