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

1

8

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

Oconnor answered 19/11, 2015 at 11:1 Comment(0)
O
13

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.

Oconnor answered 19/11, 2015 at 11:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.