Transcript from the "Gas Overview" Lesson
>> Yes, someone did incremented at least four times while we were out. So that's actually pretty fantastic. We saw we got some of that done. All right, so this is probably one of the more important little things you need to put in your brain. I'm just gonna go over some stuff, no need to program we're just gonna see how it works.
[00:00:17] Effectively it's just talking about gas. Gas is really expensive. You've probably heard this term if you're familiar enough with ethereum, it's called gwei is the standard unit for gas which is actually a non standard unit. The standard unit for ethereum is called wei one we is the fundamental unit of ether effectively, it's like our pennies every dollars 100 pennies effectively.
[00:00:39] There's 10 to the nine wei and a gwei, a gwei is not a giga chat. It is a giga wei it's a billion weis, ethers just simply 10 to the 18 weis. So when you own an ether you own 10 to 18 weis, gas is measured in these more fundamental units.
[00:00:55] Gas tends to be measured in a giga wei, are we have just called gwei from here on out. So there's two things you need to understand when it comes to gas prices. First thing is virtual machines. So I wanna just do a quick drawing on a virtual machine just in case people don't understand.
[00:01:08] And effectively when you think about it contracts are just simply a series of but, I got to take a quick break here. Did you see how straight that line is? I mean, that was free hand drawn and FDE material there. Contract is just simply a series of byte codes that need to be executed one at a time.
[00:01:26] So you can imagine that if you were to write a program that takes in text and does what the text says, you would effectively have a do while loop because that is the best loop of all time. You'd have a do while loop that inside of it would have a switch statement that would walk through your so called program.
[00:01:43] If you ever did advent of code in 2019, they had an ENT machine in which you would actually do effectively this. And it would hop around inside of your program until it gets to an endy condition, and then it would leave. And that's really all a virtual machine is.
[00:01:57] So when I write something that looks like x + 3. What's actually happening is that there's a something called an add being executed, a lot like assembly, right, there's an add. Maybe it has to load in the x for memory and then it has to put in a constant and then it probably needs to go and store this value in something else.
[00:02:55] A little bit dangerous to do go-tos but it was a lot of fun. And so that's all a virtual machine is, it interprets these things one at a time. Every single action in a theorem comes with a cost. So we can actually open up this little link that I put in there.
[00:03:07] And you can see right away an add operation requires three units of gas. And so that's, it's a hard number. So every single time you do an add, you're paying three units of gas. If you do, say a store, it could cost a lot more, if you wanna store something onto the network or onto your contract, you can store a single word or 256 bits for approximately 20,000 units of gas.
[00:03:33] Now that doesn't mean you're paying just simply 20,000 gwei, you're paying 20,000 units of gas and so what is the other side? What is the cost of gas? Well, I can just go in here and go cost of open up. That's cost of storage cost of eth gas.
[00:03:51] Go here, it'll probably open up ETH gas station, usually good way to go. It should say somewhere around in here. All right, this one doesn't give me just the gwei one. There's one that just gives you the gwei one, gosh. Ether scan, there we go. It's 205 gwei, meaning that if we're to do this an add costs three gas units right now costs 205 gwei per gas unit, and the cost of one ether is $4,000 divide that of course by 10 to the nine.
[00:04:21] And what do you get a single add operation right now cost 0.02. So if you were to add 50 items right now, it would cost $1. So, that's expensive, right? This is why a theory I'm struggling in these areas. So I have the little thing broken down right here.
[00:04:40] This is why I did tend to the nine, not 10 to the 18. Because remember, it's in gwei, it's not an ethers. So he times it by that to make it into ethers multiplied by the cost of ethers divided by wei or you can just simply reduce the formula to being this.
[00:04:55] So, if you're not familiar with maths there you go, that's an easy way to do it and so it's actually pretty expensive.