- https://www.reddit.com/r/ethereum/comments/271qdz/can_someone_explain_the_concept_of_gas_in_ethereum/
- https://www.reddit.com/r/ethereum/comments/3fnpr1/can_someone_possibly_explain_the_concept_of/
- https://www.reddit.com/r/ethereum/comments/49gol3/can_ether_be_used_as_a_currency_eli5_ether_gas/
Operation Name | Gas Cost | Remark |
---|---|---|
step | 1 | default amount per execution cycle |
stop | 0 | free |
suicide | 0 | free |
sha3 | 20 | |
sload | 20 | get from permanent storage |
sstore | 100 | put into permanent storage |
balance | 20 | |
create | 100 | contract creation |
call | 20 | initiating a read-only call |
memory | 1 | every additional word when expanding memory |
txdata | 5 | every byte of data or code for a transaction |
transaction | 500 | base fee transaction |
contract creation | 53000 | changed in homestead from 21000 |
Total cost = gasUsed * gasPrice
Frontier had a default gasPrice of 0.05e12 wei.
Example transaction cost
Let’s take a contract that just adds 2 numbers. The EVM OPCODE ADD consumes 3 gas.
The approximate cost, using the default gas price (as of January 2016), would be:
3 * 0.05e12 = 1.5e11 wei
Since 1 ether is 1e18 wei, the total cost would be 0.00000015 Ether.
可以推算出
1 gas = 0.05e12wei ?
1 gas = 0.00000005 Ether ?
重要概念的理解:Gas与Ether的联系与区别
- https://www.reddit.com/r/ethereum/comments/271qdz/can_someone_explain_the_concept_of_gas_in_ethereum/
- https://www.reddit.com/r/ethereum/comments/3fnpr1/can_someone_possibly_explain_the_concept_of/
- https://www.reddit.com/r/ethereum/comments/49gol3/can_ether_be_used_as_a_currency_eli5_ether_gas/
Gas is supposed to be the constant cost of network resources/utilisation. You want the real cost of sending a transaction to always be the same, so you can’t really expect Gas to be issued, currencies in general are volatile.
So instead, we issue ether whose value is supposed to vary, but also implement a Gas Price in terms of Ether. If the price of ether goes up, the Gas Price in terms of ether should go down to keep the real cost of Gas the same.
Gas has multiple associated terms with it: Gas Prices, Gas Cost, Gas Limit, and Gas Fees. The principle behind Gas is to have a stable value for how much a transaction or computation costs on the Ethereum network.
- Gas Cost is a static value for how much a computation costs in terms of Gas, and the intent is that the real value of the Gas never changes, so this cost should always stay stable over time.
- Gas Price is how much Gas costs in terms of another currency or token like Ether. To stabilise the value of gas, the Gas Price is a floating value such that if the cost of tokens or currency fluctuates, the Gas Price changes to keep the same real value. The Gas Price is set by the equilibrium price of how much users are willing to spend, and how much processing nodes are willing to accept.
- Gas Limit is the maximum amount of Gas that can be used per block, it is considered the maximum computational load, transaction volume, or block size of a block, and miners can slowly change this value over time.
- Gas Fee is effectively the amount of Gas needed to be paid to run a particular transaction or program (called a contract). The Gas Fees of a block can be used to imply the computational load, transaction volume, or size of a block. The gas fees are paid to the miners (or bonded contractors in PoS).
来源:oschina
链接:https://my.oschina.net/u/1263162/blog/759271