Giter Club home page Giter Club logo

upgrading-smart-contract's Introduction

Upgradig Smart Contracts

In This Section We Will Learn How to Upgrade Smart Contracts.

Remembers Points ๐Ÿ’ก

  • Upgrading Smart Contract Does Not Compromise The Immutability of Smart Contract in Blockchain

  • In This Chapter We Will Be Using @openzeppelin/hardhat-upgrades Package For Upgrading our Smart COntract

  • When We Initially Deploy Contarct, It Deploy Three Contracts in Real.

    • Implementation Contract (Our Original)
    • ProxyAdmin Contract
    • Proxy Contarct

    We Deal With Proxy Contarct For Calling Our Specified Methods

  • When We Deploy a Contarct Using deployProxy Method, That Contract Instance Can Be Upgraded Later

  • Only The Address That Originally Deployed Has the Rights to Upgrade

  • On Upgrading, The State Values (Vairables) and Contarct Adress etc Remains Same as The Previous One

Necessary Packages ๐Ÿ“ฆ

    npm install @nomiclabs/hardhat-ethers
    npm install @nomiclabs/hardhat-waffle
    npm install @openzeppelin/hardhat-upgrades
    npm install ethereum-waffle
    npm install ethers
    npm install hardhat

And Dont Forget to Add Below Lines in hardhat.config.js

require("@nomiclabs/hardhat-waffle");
require("@openzeppelin/hardhat-upgrades");

Procedure ๐Ÿงช

npm init -y
npm i hardhat
npx hardhat

Open Terminal and Run

npx hardhat node to Run Hardhat Local Blockchain

Now Deploy Our Contarc to Localhost

npx hardhat run Scripts/DeployOld.js --network localhost`

Now Copy The Address of This Deployed Smart Contract

Now Open Terminal and Type

npx hardhat console --network localhost

const A1=await ethers.getContarctFactory("Old")
const A2=await A1.attach("0x9AB3SHDJD .... ") //Contract Address
(await A2.Get()).toString() // Will Print Value of Num (1)

// Now Deploy Our New Contract
npx hardhat run Scripts/DeployNew.js --network localhost

//Now Run Again
const B1=await ethers.getContarctFactory("New")
const B2=await B1.attach("0x9AB3SHDJD .... ") //Contract Address
(await B2.Increment())
(await A2.Get()).toString() // Will Print Value of Num (2)

upgrading-smart-contract's People

Contributors

hydraphyzer avatar

Stargazers

 avatar

Watchers

 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.