Solidity, Blockchain, and Smart Contract Course – Beginner to Expert Python Tutorial - Ep51

[cpp] Time: 2025-07-11 11:56:42 Source: AIHackNode Author: article Click: 182 times
greatjust use the most recently deployed mockV3 aggregator and journeys to marsthen of course wedon't we no longer need to set this as avariable and that looks a little bitcleaner and we'll make this a little bitmore efficient so this deploying MOX bitthough is going to be something that sothis deploying MOX bit though is goingto be something that we're actuallygoing to do relatively frequently let'seven move this print statement up hereso instead what I like to do is put thiswhole mock deploying bit in its ownfunction in our helpful scripts so let'sopen back up our helpful scripts we'lldo a new function calleddef deployMox and we'll just paste that code inhere of course this means that in ourhelpful scripts we're going to have toimport Mach V3 aggregator we'll alsohave to do from web3 Port web 3 and instead of accountwe'll just use this get account functionnow back in our deploy script we canjust delete this whole part replace itwith deployMox and then import deploy MOX from ourhelpfulscripts and then we can also delete thisimport now let's remove some of thesecomments if you'd like this is startingto look a lot more sophisticated andthis is great because now we have a wayto deploy based off if we're on a livechain or a development chain and thenone more thing I like to do so thateverything isparameterized I like to set these asstatic variables in the top of ourhelpful scripts so I'll set decimalsequals 18 and then I'll setstarting price equals 2000 and then I'llhave mock V3 aor to deploy to Desweb 3.2a to starting price here so solet's say now that I wanted to deploythis to my own ganache instance wellwhat we could do is we could open up ourganache here do quick start and we'lljust quickly create our own gachblockchain in our script let's go aheadand just run this deploy script againlet's see what happens instead ofbrownie spinning up its own ganache hereit says attached to local RPC clientlistening at at and then this addresshere brownie is smart enough to detectif you're running your own ganachinstance here and will automaticallyattach itself to it knowing that that isgoing to be a development environment ifwe go to our ganache we'll see we havetwo transactions which are going to becontract Creations we're going to createa price feed contract and then also ourfundme contract so this is great this isgreat for testing quickly and locallybut there is an issue with this fordevelopment networks again browniedoesn't keep track of those so in ourbuild folders if we go to deployments weonly are saving stuff from the rink bechain here so we would need to tellbrownie hey there's another Network thatwe want you to work with and we want youto remember the deployments to thatchain so what we can do is we can add anew network to our brownie network listrememberbrownie networks list we have all thesedifferent pieces in here these are theones that brownie is going to notremember and these are going to be theones that brownie remembers so let's saywe want to deploy to a ganach chain andwe want brownie to remember thosedeployments well we can add a networkhere and this is going to be how we addany blockchain that we want any evmblockchain like Avalanche like polygonEtc to add a new network to the brownienetworks is we'll run brownie networksadd we'll choose development or ethereumwe're going to choose ethereum becausewe want this to be a persistent Networkdo ethereum we'll give it a name I'mgoing to call thisgachlocal we need to give it a host AKA andHTTP address which we know is righthere then I'm just G to make thislowercase and then a chain IDwhich for this we know is1337 enter now if I do brownie networklist I see a new blockchain calledganach local and this is going to reachout to our ganos UI or our ganachcommand line depending on what we'rerunning now just to note we are going tobe deploying to this ganach UI or ganachCLI a lot for the rest of this lesson soplease keep your ganache instancerunning now what I can do is I can runbrownie run scripts deploy pi-- Networkganachlocal let's see what happens of coursewe run into our our first issue ganachlocal isn't development so it's going togo ahead and try to pull from our configfile we don't want this we want toactually deploy a mock for our localganach if a mock hasn't been deployed sowhat we can do is we can extend ourdefinition of what a developmentenvironment is in our helpful SC scriptswe can add a flag in here we'll saylocal blockchainenvironments equals and this will be alist we'll say development of coursewill be one but we can also saygach local will be another and now wecan import this local blockchainenvironments into our deploy so from atthe top from scripts. helpful scripts doa comma here paste that and save M getsreformatted which is really nice andinstead we'll say if network. showactive not in local blockchainenvironments then go ahead and pull fromthe config what this is saying is it'ssaying if whatever Network that we're onif it isn't development or ganach localthen go ahead and use a config if it isone of these two we're going to go aheadand deploy a mock here now that we havethat let's try this again rowny runscripts deploy py--NetworkG local and we run into a differentissue we're saying hey you don'tactually have enough gas well why isthis let's look at our get accountfunction aha this one is also lookingdirectly for this development chain thisone will say if network does show activeisin local blockchain environments thenreturn accounts zero so we're saying ifthe network we're working on isdevelopment or ar ganach local then justreturn accounts zero so let's try thisokay we're getting closer now we'rerunning to this key error ganach localwell we do know how to fix that as wellin our config We'll add this new networkwe'll say ganach local and we'll setverify to false so let's try this onemore time perfect now mocks have beendeployed and our funme has been

(Editor in charge: ai)

Related content
Wonderful recommendations
Popular Clicks
Friendly links