Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep274

[kotlin] Time: 2025-07-11 11:22:46 Source: AIHackNode Author: c Click: 69 times
using instead of running our hardhat and chris langan theorynow we should be good to go solet's create a new folder calledcontracts and in here we're going tocreate a new file called box. soul andit's this contract that's going to beour implementation or our logic contractso we'll say pragma solidity CAR0.8.7 contract box we'll say U 256internal value we'll do a vent valuechanged U 256 new value we'll dofunction store U 256 newvalue this will be a public function wesay value equals new value so this storefunction is going to update our variableat storage slot zero internal and thenwe'll justemit valuechanged with that newvalue and and then we'll just createfunctionretrieve which will be a public viewreturns a uint 256 we'll just do returnvalue and then we're going to create anewfunction called version and this will bea public cure and that returns a un 256and we're just going to have this returnone so our box contract here is going tobe version one now we're going to copyall this code paste it into a boxv2. rename it to contract box V2 we'regoing to update the version to versiontwo here and we're going to create a newfunction calledincrement and this will be a publicfunction and we'll say value equalsvalue + one and then we will emit avalue changed event with value we'regoing to have one contract addressoriginally used the logic in box andthen we're going to upgrade it to thelogic in box V2 and we're going to learnhow to use all the tools that we've beenworking with here to add this logic andcreate this logic and let's just makesure this works we'll doyarn Aradcompile so let's make a readme.md we'llsay one we're going to upgrade box tobox V2 so we're going to make a proxycontract that's going to point to boxand then later on we're going to updateit to point to box V2 right so we'regoing to start it up pointing to boxthen we're going to have it point to boxV2 and that's how we're going to upgradeit one of the first things we're goingto need to do is deploy a proxy we candeploy a proxy manually ourselves and wecan build the proxy contracts and do allthat stuff that's our first option hardhat deploy also comes buil in withdeploying and upgrading proxies itselfwhere we can just specify that we wantto use a proxy and we can specify thetype of proxy that we want to use sonumber two is just saying using hardheaddeploys buil in proxies and then numberthree is open Zeppelin actually has anupgrades plugin which allows you towrite some really simple scripts thatallows you to have a really simple APIlike upgrades. deploy proxy and thenupgrades. upgrade proxy now for thissection we're going to be doing thehardhead deploys built in proxieshowever in the GitHub repo associatedwith this if you go to scripts there'supgrade examples that will show you howto use the open Zeppelin upgrades pluginand we're not going to do deploy apprproxy manually manually because weessentially just showed you how to dothat in our subl lesson so we're goingto show you this we're going to show youthe hardhead deploys built in proxiesand if you want to use the open Zeppelinupgrades plugin that is available in theGitHub repo as well so let's go aheadand do this so we're going to go aheadwe're going to make a new folder ourdeploy folder and first we're going tomake a new file called 01 deploy box.js and this is going to look reallysimilar to everything we've been doingso far so module. exports equals asyncfunction we're going to get get namedaccounts anddeployments an arrow function we'll saycon deploy comma log equalsdeployments constdeployer equals await getnamedaccounts do a little logging like thisand then we'll say const box equalsawaitdeoy box comma we'll say fromdeployer comma args like this we'll sayweit con confirmations is going to benetwork. config do block confirmationsformations and yep we got to grab constfrom hard hatand then we can add the parameter inhere for proxies and this is where wecan add a ton of information so like Isaid we're going to use the transparentupgradeable proxy from open Zeppelinwhich if we want to use it we're goingto have to add open Zeppelin so we'll doyarn add- ddev at open Zeppelincontracts and we can tell our hardheadto deploy this box contract behind aproxy we'll say the proxycontract is going to be theopenZeppelintransparent proxy and we're also goingto do a via admin contract so instead ofhaving an admin address for the proxycontract we're going to have the proxycontract owned by an admin contract anddoing it this way is considered a bestpractice for a number of reasons butwe'll name this admin contract box proxyadminand the artifact for this box proxyadmin so we'll need to create a boxproxy admin contract to be the admin ofour box so in our contracts foldercreate a new folder calledproxy and in here a new file called boxproxy admin. and this is going to be theadmin contract we're going to have forcontrolling the proxy of our box so inbox proxy admin. soul we'll dospdxlicenseidentifierMIT pragma solidity carat0.8.7 we'll say contract box proxy adminlike this great and once again we'regoing to use one of the open Zeppelintools in the transparent folder theyhave a proxy admin. Soul which is goingto be essentially what our box proxyadmin is going to B it has somefunctionality it has some functions inhere like change proxy admin upgradeupgrade and call for dealing withupgradeable contracts so we're going toimport it we'll do importatop Zeppelin contracts proxytransparent SL proxy admin. soul andwe'll say our box box proxy admin isproxy admin like this and to have thisbox prox admin work with the hard atdeploy plugin our Constructor needs totake an address owner as an inputparameter but we're just going to leavethat blank and then and then we need todo the proxy admin which is just goingto be blank as well and that's it that'sall we're going to do box proxy admincontract which just has all of thefunctionalities to do upgrades andchange proxy admin and all this stuffwe're going to deploy

(Editor in charge: web3)

Related content
Wonderful recommendations
Popular Clicks
Friendly links