Skip to content

solidity proxy contract explain ant implementation.

Notifications You must be signed in to change notification settings

aabdullah29/proxyContracts

 
 

Repository files navigation

Initial commands: => npm init => npm install hardhat => npx hardhat => yarn

Then install these Modules: => yarn add @nomiclabs/hardhat-ethers => yarn add @openzeppelin/hardhat-upgrades

Run hardhat node and this shall not stop: => npx hardhat node

Open parallel terminal and run the script to deploy the smart contract: => npx hardhat run --network localhost scripts/Box-script.ts

Copy the contract address and comment it in the contrac file. open the hardhat console: => hardhat console --network localhost

Create const of the contract to use its functions: => const Box = await ethers.getContractFactory("Box"); => const box = await Box.attach('//paste contract address here');

Now you call the functions of the deployed smart contracts, for example: => (await box.retrieve()).toString();

Now you want to deploy the updated contract with some new functionalities. Write the script of the contract and add the address of the previous contract there.

Then run the script of the second contract: => npx hardhat run --network localhost scripts/Box1-script.ts

open the hardhat console: => hardhat console --network localhost

Create const of the contract to use its functions: => const Box1 = await ethers.getContractFactory("Box1"); => const box1 = await Box1.attach('//paste contract address here');

Now you can use the new functionality added in the second contract, for example: => await box1.increment();

Now you can do this method again and again and update the contract whenever you want to and the contract address will remain the same. You can also follow the documentation of this article: https://dev.to/yakult/tutorial-write-upgradeable-smart-contract-proxy-contract-with-openzeppelin-1916

About

solidity proxy contract explain ant implementation.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 56.3%
  • Solidity 32.5%
  • JavaScript 11.2%