How much ether
do you need to pay for a transaction?
- You pay
gas spent * gas price
amount ofether
, where gas
is a unit of computationgas spending
is the total amount ofgas
used in a transactiongas price
is how muchether
you are willing to pay pergas
Transactions with higher gas prices have a higher priority to be included in a block.
Unspent gas will be refunded.
There are 2 upper bounds to the amount of gas you can spend
gas limit
(max amount of gas you're willing to use for your transaction, set by you)block gas limit
(max amount of gas allowed in a block, set by the network)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Gas {
uint public i = 0;
// Using up all of the gas that you send causes your transaction to fail.
// State changes are undone.
// Gas spent are not refunded.
function forever() public {
// Here we run a loop until all of the gas are spent
// and the transaction fails
while (true) {
i += 1;
}
}
}