Let's say we call the function:
function nice(uint a) public returns(uint256){
k = 100;
z = 100;
f = 100;
require(a == 5);
o = 100;
s = 100;
return 170;
}
Let's say we passed in a = 15
. So, what will happen is transaction is going to be reverted due to require
. Now, the transaction cost for the first 3 lines of code(assigning 100 to k,z,f) takes 81000 (this includes transaction data) too. It seems like after transaction is done, from my account, only 81000*price of gas is taken from my balance, which is correct.
What I am curious about is how this happens. Specifically,
- does it take all my gaslimit * gas price from my account, executes the code, and whenever it's done, it checks if there's any remaining and if there's, it gives back the remaining value. In above case, that could happen, since because of
require
, it wouldn't make us spend all gas. But if this is how it does, why don't I see the balance reduction and then increase again between pending transaction and finished transaction states ?
OR
- I have no idea how else it could do. Any idea ?