Current location: Homepage > swift > Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep49

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

2025-07-11 11:20:58 [python] Source: ByteGenius
after this transaction goesthrough we should see this number gofrom 0.02 to0.04 now after we wait a brief delay wedo indeed see the balance has gone up to0.04 which is zane lowe mileyexactly what we we'dexpect awesome so our funding mechanismis working correctly and if we go downinto our array and ourmapping we do address to array and wepaste our address we should see the fournumber show up and if we go to fundersof zero we see our address and if we goto funders of one we also see ouraddress and we see that and we see thiscall going through if we go to fundersof two in our log over here we actuallysee that we get an error an optimizationthat we could make to our contract inthe future is to check to see if anaddress is already in the funders arrayand then not add it if it's alreadythere now let's go ahead and try to callthis withdraw function but let's try tocall it with a different address thanthe address we originally deployed thiscontract with so to do that scroll allthe way to the top of this here and I'mgoing to go to mymetamask and I'm going to switch to asecond account and hitconnect now our remix should be updatedwith the new account that's in hereyou'll see that if I switch back toaccount one it switches back to accountone so long as they're both connectedyou can see which accounts are connectedto Applications by clicking thisconnected button and see which ones areconnected if you ever want todisconnected account you can click thethree little dots and hit disconnect theaccount and now we can see that thisthis account is not connected howeveraccount two is connected let's go backto account one and connect account oneso that both of them are now account areconnected but we'll switch to accounttwo let's switch to account two becauseagain account two isn't the owner ofthis contract we scroll down to owner wecan see owner is 0x1 066 somethingsomething and account two is 0x 043something somethingawesome so what do you think will happenwhen we hit withdraw here well ourmodifier only owner should kick in andwe should get notified that if we sendthe transaction we'll get this errorsender is not owner so let's try it ahgas estimation failed we do get thiserror sender is not owner which isperfect this is exactly what we want wecould absolutely send this transactionif we wanted to but that would just be awaste of gas because this transaction isgoing to fail however if we switch backto accountone and we hitwithdraw menam mask will pop up enablingus to hit confirm and withdraw The Etherout of this contract address now if welook at this contract address on etherscan after a brief delay we'll see thebalance go from0.04 back down to zero and we'll see ourWallet balance go up from what it isback to 0 .04 plus what it was and aftera brief delay you can see our balance isindeed back down to zero in our contractnow if we do address to amount for ourwallet address that was doing thefunding it's back down to zero and if wetry to check the address of funders atindex zero we get call to funders fundmeered execution revertedwe've completed all the basics of thesection that I wanted to go through andyou should be incredibly proud ofyourself for getting this far you'vejust deployed a really Advanced smartcontract we're using a library and chainlink contracts to build some of the mostpowerful applications in the planetwe've learned to use a library for anytype we want in our smart contractswe've learned more about multiplicationand then units of measure in solidity insmart contracts we've learned aboutmappings more about arrays what theConstructor does we've learned how tosend money we've learned about for Loopswe've learned about the different wayswe can actually send money at least froma low level and we've learned aboutmodifiers this section is one of thetoughest sections in this course so ifyou completed this you should beincredibly excited we're going to gothrough our code now and we're going tomake a number of tweaks now this sectionwe are going to do a little bit moreadvanced solidity here so if you get alittle bit lost don't sweat it too muchand feel free to try some of this stuffin the future on yourown we're going to modify this contractto make it a little bit moreprofessional it's not going to be end toend amazing but it's going to be alittle bit better and you'll see why ina minute so the first thing that we'regoing to do is we're looking we're goingto look at some of these variables herein particular owner and minimum USDowner gets set one time in our contracthere and then it never changes againminimum USD gets set one time evenoutside of the Constructor if we havevariables that only get set one time wecan actually use some tools and solidityto make them more gas efficient for nowlet's compile our fundme contract andthen deploy it to a JavaScript viralmachine remember we can go ahead anddeploy it right now however funding andwithdrawing and doing any of the moneystuff isn't going to work because againwe don't have a chain Lake Network onour JavaScript VM so those aren't goingto work so well but for what we're goingto do right now we don't really care somuch here's what we do care about we docare about how much gas this costs toactually send we do care about how muchgas this costs to create right nowcreating this contract costs about$859,000 gas and we're going to add acouple of Tricks right now to bring thisnumber down we're going to add somestuff back in in a bit which will bringit back up but for now we're going tolearn some tricks to bring this numberdown the two tricks that we're going tolearn are the constant keyword and theimmutable key keyword in their soliditythere are two keywords that make it sothat your variables can't be changed andthose keywords are constant andimmutable you can learn more about themin the solidity documentation if youassign a variable once

(Editor: ai)

Recommended articles
Hot reading