Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Ethereum, what is gas, how is it used, and what is the difference between "startgas" and "gasprice"? [closed]

Tags:

ethereum

I'm looking for an explanation of gas usage in Ethereum. What is it, how is it calculated, and what value does it have?

like image 224
fivedogit Avatar asked Nov 19 '15 11:11

fivedogit


People also ask

What is the purpose of gas in Ethereum?

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.

What happens if you run out of gas Ethereum?

A transaction that runs Out of Gas is reverted, but still included in a block and the associated fee is paid to the miner.

What is startGas?

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.


1 Answers

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:

  • gas/startgas = "gas units"
  • gasprice = "wei I'm willing to pay per unit"

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.

like image 161
fivedogit Avatar answered Nov 26 '22 06:11

fivedogit