Current location: Current location: Home > swift > Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep113 Text
Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep113
[swift] Time: 2025-07-11 11:52:25 Source: AIHackNode Author: javascript Click: 86 times
us toget the storage at any one of theseslots and eminem 2024 newsthis is to reinforce that evenif you have a function as private orinternal anybody can still read itanybody can read anything off theblockchain and you can test it exactlywith this if you go ahead and get clonethat or copy paste the code yourself youcan then run yarn hard at deploy D- tagsstorage and you'll run the deploy scriptfor that storage and you'll see printingout the location of storage in eachstorage slot with a fun contract that wemade as anexample now you might of course beasking okay Patrick why are you tellingme all this we're just trying to getthis gas price down why are you tellingme all about this storage thing well thereason I'm telling you all about thisstorage thing anytime you read or youwrite to and from Storage you spend aton of gas remember how I said when wecompile our code we compile it down tosome crazy weird bite code well let meshow you on remix what this looks likewe can go to compilation details we cango to bite code and we see this weirdhex object zero blah blah blah but wealso see these things called op codesnow this bite code here represents theseop codes each one of these op codesrepresents a small piece of everythingin this bite code and in fact in ourhard hat we can go to artifacts buildinfo and we can see we can see these opcodes in the build info we can do acommand F or a control F for opcodes and we can see op codes fordifferent contracts these op codesrepresent what the machine code is doingand they represent how muchcomputational work it takes to actuallyrun our code and do stuff with our codethe way that gas is actually calculatedis by these op codes there are a couplelists here but here's one that I'm goingto use this evm op codes and againthere's a link to this in the GitHubrepo associated with this lesson well ifwe scroll down we can see exactly howmuch it costs for each one of these opcodes so for example anytime we add itcosts three gas anytime we multiplythat's five gas subtracting three gasgas we have all of these op codes thatcost different amounts of gas and in ourfunctions here's kind of a a samplecontract if we're doing adding anytimewe add it's going to cost three gasanytime we save to memory it's going tocost gas from some other op codes theseop codes combined show us how much gaswe actually use now let's look at a lotof these op codes and how much they cost3 5 10 3 3 balance is 700 100 so gettingthe balance is is a ton of gas let'skeep going getting the size of anaccounts code is a lot of gas copying Anaccounts code into memory but oh mygoodness what is this save word tostorage costs a ton of gas that is20,000 gas and SL load load word fromStorage costs 800 gas these are two ofthe most important op codes S load and sstore which stand for store storage loadand storage store anytime one of theseop codes fires we're spending 800 or20,000 you know there's a big Asterthere cuz that can change a lot butwe're spending a ton of gas anytime wework with storage as developers anytimewe work with some stuff in storage wewant to go boy this is about to cost mea lot of gas and a best convention formaking sure we know that we're workingwith a storage variable and we're aboutto spend a lot of gas is to append an Sunderscore right before them whichstands for storage right so we're sayingaddress to amount funded is going to bea storage variable funders is going tobe a storage variable owner is not goingto be a storage variable it's a mutablea best practice for immutable variablesis prefixing it with an I underscoreconstant values are also not in storageso for constant values we want to keepthem caps locked like that aggregator V3interface public price speed yep youknow it that is going to be a storagevariable so we want to append an sorewith it so we're going to do a littlebit more refact we've appended theseappropriately to update everything soinstead of owner it's going to be ioreowner and as a developer we'll read thisand we'll go ah this is going to be muchcheaper than a regular variable okaythat's great I'm going to work with thisthis iore owner for my modifier awesomeis owner anywhere else in here ah okayright in the Constructor iore owner ismessage. sender price feed is a storagevariable we should as developers weshould see the sore when reading thisand go okay we're spending a lot of gasto store this perfect okay great let'skeep going great we've updated all theowners okay well what about address toamount funded in vs code if you docommand F or control F and you hit thislittle down arrow you can actually findand replace all of these address toamount funded withsore address to amount funded hit itlike that and since I updated one I gotto backspace that one now so now theseare all updated let's do the same thingwith s funders let's update everywhereit has funders just to be S funders andwe probably doubled up here yep let'sundo that we already updated all the eyeowners so now let's update all the pricefeeds so let's look for Price feed andwe'll update it with S price feed andthen we probably doubled up right hereso we'll undo that okay great now thatwe've updated everything in here we canscroll down and we can look oh whoops soI doubled up there too sorry we can wecan read through our code and go okaywhere are we reading and writing tostorage way more often than we probablyneed to and that's when we get to thiswithdraw function which seems rathersuspect to reading and writing tostorage a lot so let's take a look atwhat we're doing here okay so first ofall I can see that we're doing a forLoop here and every time we do a
(Editor in charge: kotlin)
Artificial Intelligence Full Course _ Artificial Intelligence Tutorial for Beginners _ Edureka - Ep19Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep259
Related content
- Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep247
- Solidity, Blockchain, and Smart Contract Course – Beginner to Expert Python Tutorial - Ep95
- Web3 Incorporation in Panama (A Legal Guide) - Ep2
- Solana Developer Bootcamp 2024 - Learn Blockchain and Full Stack Web3 Development - Projects 1-9 - Ep8
- Solana Developer Bootcamp 2024 - Learn Blockchain and Full Stack Web3 Development - Projects 1-9 - Ep75
- Artificial Intelligence Full Course _ Artificial Intelligence Tutorial for Beginners _ Edureka - Ep16
- Solidity, Blockchain, and Smart Contract Course – Beginner to Expert Python Tutorial - Ep74
- Bloodhound Q50 Tells His Life Story (Full Interview) - Ep13
- GenAI Essentials – Full Course for Beginners - Ep136
- Bloodhound Q50 Tells His Life Story (Full Interview) - Ep14
- Web3 Incorporation in Panama (A Legal Guide) - Ep1
- GenAI Essentials – Full Course for Beginners - Ep29
- Solana Developer Bootcamp 2024 - Learn Blockchain and Full Stack Web3 Development - Projects 1-9 - Ep46
- Solidity, Blockchain, and Smart Contract Course – Beginner to Expert Python Tutorial - Ep68
Wonderful recommendations
- Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep296
- GenAI Essentials – Full Course for Beginners - Ep123
- GenAI Essentials – Full Course for Beginners - Ep167
- GenAI Essentials – Full Course for Beginners - Ep119
- GenAI Essentials – Full Course for Beginners - Ep70
- Bloodhound Q50 Tells His Life Story (Full Interview) - Ep9
Popular Clicks