Current location: Home > solidity > Solidity, Blockchain, and Smart Contract Course – Beginner to Expert Python Tutorial - Ep107 Text
Solidity, Blockchain, and Smart Contract Course – Beginner to Expert Python Tutorial - Ep107
Time: 2025-07-11 11:43:43 Source: Codora.ai Author: java Reading: 788 times
encode any function callhere we can tech revolution 2025just saytransaction equals that proxy admincontract.upgrade so it has an upgrade and call italso just has a regular old upgrade sowe'll just call upgrade and we'll giveit the proxy doaddress the new implementation addressand thenfrom account now if it doesn't have aproxy admin contract this means that theadmin is just going to be a regular oldwallet well what do we do do then wellfirst check to see if it has aninitializer still and if it does we needagain to encode that function call wecan just copy and paste that there thenonce that's encoded we can just calldirectly off the proxy contract we'regoing to call exactly what the proxyadmin contract is calling which going tobe proxyupgrade to and call we're going to giveit the new implementation address theencoded functioncall and then fromaccount let's wrap this all up in a bigelse so if proxy admin contract do thisstuff else do thisstuff if initializer do that otherwisewe can just do transaction equals proxydo upgrade two and we just add that newimplementationaddress fromcount and then we'll finally returntransaction so I know that there is alot here but we're really just makingthis upgrade function really General wecould always just know okay if we we'regoing to use a proxy admin let's just doit like this okay no we're not going touse a proxy admin we're also not goingto use an initializer great it wouldjust look like this but this isessentially all that we have to do sonow that we now that we have our upgradefunction we can go ahead and use it hereso we need to give it an account a proxya new implementation address so we'llsay account so we'll sayupgrade transaction equals upgradeaccount we need a proxy and a newimplementation address we're going togive it theproxy and we're going to give it box b2.address for that new addresswe do have a proxy admincontract so we'll sayproxyadmin contractequals proxy admin and we don't have aninitializer so we can leave that partblank of course we need to import thisupgrade function from our helpfulscripts and this is all that we need sonow we can doprint proxy has been upgraded and whatwe could do now is we can do proxy boxequalscontract. fromAI we'll call it boxV2 we give it the proxy do address boxv2.ABI and now we should be able to callproxy box.incrementfrom account and then we canprint proxy box. reretrieve and this should now be one andwhat we'll actually see is that thiswill return two why does it return twowell in our original proxy box we storedone so it started with one we thenupgraded to this new contract and thenlet's actually just do a weit of coursewe upgraded to a new contract right herehowever the storage of that contractstayed in the proxy so that one stayedin the proxy so even though we upgradedthe contract there's still one stored atthe location of storage so then when wecall increment now and then we callretrieve it's going to go from one totwo so let's go ahead and and run thisbrownie runscripts Loy upgradeenter and boom that is exactly what wesee output here this is an incrediblyincredibly powerful and advanced featureand if you've gotten to this point youare on the border of being one of themost powerful smart contract Engineerson the planet huge congratulations forgetting this far but we're not quitedone we of course need to write sometests because that is what's going tomake sure our project always stays insync and always stays up to dat so let'swrite a couple of tests here so let'screate a new file we'll call testboxproxy dopy and for this we're reallyjust going to test to see that ourcontracts work we're going to see thatthis box actually is going to workcorrectly so let's create a new test defproxy delegatescalls so we're going to make sure thatwe actually can delegate calls to ourcontract we're going to say accountequals getaccount which means we got to dofrom scripts. helpfulscripts import get account then we'regoing to do boxequals box.deoy of course this is going to befrom account since we're using box we'regoing to do from brownieimport box we're going to do this proxyadmin so we're going to say proxy adminequals proxyadmindeploy of coursefromcount let's import proxy admin frombrownie all right so now we'll do theBox encodedinitializerfunction or whatever we called it beforethis is going to be thatencode function data which uh my vs codeactually automatically imported thanksvs code and again we're leaving it blankuh because we're not actually going tohave a store there and then we're justgoing to go ahead and run thatdeployment so we're going to say proxyequals trans parentupgradeableproxy and we're going to grab this frombrownie.deploy say again the box.address proxy admin.address box encoded initializerfunction we say from account and thenwe'll give this a gaslimitof 3 1 two 3 now we're going to put theABI on top of this proxy so we're goingto say proxy boxequals contract. from ABI we going toname itbox this is going to be with the proxyaddress and the box.ABI of course we're going to need toreport contract from Brownie and okay sonow we canassert proxybox.retrieve if I spelled that right isequal to zero then we're going to doproxybox.store do one and this will be fromaccount and then we're going to assertagain this proxy box. retrieve shouldnow equal one so we're using this proxycontract we've slapped the AI on top ofit and this should work so we're justtesting to see that our proxy is workingcorrectlyso we can go ahead and test this thenwith rounding test and beautiful itpassed now let's go ahead and create anew script for testing the upgradescreate a new file call it test box V2upgrades. piy and let's do it call deftest proxyupgrades so account is going to be equalto get account hopefully at this pointyou're getting pretty good at writingthese these tests from scripts. helpfulscripts report and of course we want toadd this innitpy just in case you forgot so nowwe're going to import getaccount perfect so we have our accounthere now as you can
(Editor in charge: java)
Latest content
- ·Full interview_ Donald Trump details his plans for Day 1 and beyond in the White House - Ep3
- ·Getting started with Web3 in 2025 _ Deep Dive Explainer - Ep4
- ·Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep158
- ·Solana Developer Bootcamp 2024 - Learn Blockchain and Full Stack Web3 Development - Projects 1-9 - Ep80
- ·Harvard CS50’s Artificial Intelligence with Python – Full University Course - Ep3
- ·Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep248
- ·Solana Developer Bootcamp 2024 - Learn Blockchain and Full Stack Web3 Development - Projects 1-9 - Ep42
- ·Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep259
- ·Harvard CS50’s Artificial Intelligence with Python – Full University Course - Ep5
- ·Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep182
Hot content
- ·Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep141
- ·Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep261
- ·Web3 Developer in 2024 Roadmap_ Solidity, Smart Contract, and Blockchain Development [Full Course] - Ep10
- ·Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep233
- ·GenAI Essentials – Full Course for Beginners - Ep26
- ·Getting started with Web3 in 2025 _ Deep Dive Explainer - Ep6
- ·Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep92
- ·Solana Developer Bootcamp 2024 - Learn Blockchain and Full Stack Web3 Development - Projects 1-9 - Ep77
- ·GenAI Essentials – Full Course for Beginners - Ep45
- ·Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep73