I'm looking for an explanation of gas usage in Ethereum. What is it, how is it calculated, and what value does it have?
A gas fee is a blockchain transaction fee, paid to network validators for their services to the blockchain. Without the fees, there would be no incentive for anyone to stake their ETH and help secure the network.
A transaction that runs Out of Gas is reverted, but still included in a block and the associated fee is paid to the miner.
The gas or startGas is the amount of gas you send along with your transaction (the gas parameter of sendTransaction ). There is a fixed amount of gas a computational step consumes. The remaining gas is refunded. For eg, transferring ether consumes 21000 gas.
In Bitcoin, every transaction creates the same amount of “work” for the network. In Ethereum, different transactions have different costs to the network in storage, processor and memory usage, so these transactions need to be “charged” accordingly. Best official(ish) explanation I’ve found is here (“gas” vs “gasprice” is the first bullet): https://github.com/ethereum/wiki/wiki/Design-Rationale#gas-and-fees
Currently (11/20/15) the max gas one can spend with a transaction is 3141592 units. The minimum price per unit is 50000000000 wei. (0.00000005 ether). So, the amount of ether sent as gas in a sample tx might go like this: 3141592 units * 50000000000 wei/unit = 157079600000000000 wei (0.1570796 ether).
Example use (https://github.com/fivedogit/solidity-baby-steps/blob/master/contracts/58_indexOf.sol):
indexof.indexOf.sendTransaction("I am cool", "cool", {from:eth.coinbase,gas:3141592, gasprice:50000000000});
Think of it this way:
Whatever gas is spent executing transactions is paid to the miner of the block containing the transaction.
Note: Gas and Ether are ultimately the same thing. What makes gas “gas” is how it’s used -- as payment for a transaction.
UPDATE: 12/8/2015: Unused gas is automatically and immediately refunded.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With