在以太坊中,gas是什么,如何使用,"startgas"和"gasprice"有什么区别?

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

我正在寻找以太坊中 gas 使用的解释。它是什么,如何计算的,有什么价值?

在比特币中,每笔交易都会为网络创造相同数量的“工作”。在以太坊中,不同的交易在存储、处理器和内存使用方面对网络的成本不同,因此需要对这些交易进行相应的“收费”。我找到的最好的官方(大概)解释在这里(“gas”与“gasprice”是第一个项目符号): https://github.com/ethereum/wiki/wiki/Design-Rationale#gas-and-fees

目前 (11/20/15) 一笔交易可以花费的最大 gas 是 3141592 个单位。每单位最低价格为50000000000 wei。 (0.00000005 以太币)。因此,在样本 tx 中作为气体发送的以太币数量可能如下所示: 3141592 单位 * 50000000000 wei/unit = 157079600000000000 wei(0.1570796 以太币)。

使用示例 (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});

这样想:

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

执行交易所花费的 gas 将支付给包含该交易的区块的矿工。

注:Gas 和 Ether 本质上是一回事。使天然气成为“天然气”的是它的使用方式——作为交易的支付。

更新:2015 年 12 月 8 日:未使用的气体会立即自动退还。