W3Schools



我想要使​​用的以太坊应用程序谈论需要“气体”运行。什么是天然气,我从哪里买到它?

transactionsgaseconomicsterminologydenial-of-service
7个回答
7

天然气基本上是运行交易或合同的内部定价。

每笔交易或合约的天然气价格设置为处理以太坊及其EVM(以太坊虚拟机代码)的图灵完备性质

因此,交易或运营越复杂,其成本就越高。


44

短:

天然气是在以太坊上进行的每项操作的执行费用。它的价格以以太表示,由矿工决定,矿工可以拒绝以低于一定的汽油价格处理交易。要获得燃气,您只需将以太币添加到您的帐户即可。

long:

以太坊在区块链上实现称为以太坊虚拟机(EVM)的执行环境。当您运行分散式应用程序(dApp)时,每条指令都在网络的每个节点上执行。这有一个成本:对于脚本可以执行的每个操作,都有一个指定的成本,以气体单位数表示,您可以在EVM规范中看到。

一个单位天然气的价格由矿工决定,目前约为5至21 GWei (One GWei is 10^9 Wei or 10^-9 Ether). Ethereum uses ether as its internal currency/token. Your accounts holding are expressed in ether. When you deploy a contract, or execute a transaction the gas will be taken from your account balance. You are free to specify a gasprice, or keep the suggest one.


254

“Gas”是以太坊中使用的特殊单位的名称。 It measures how much "work" an action or set of actions takes to perform: for example, to calculate one Kekak 256 cryptographic hash it will take 每次计算哈希值时为30气体, plus a cost of 6 more gas for every 256 bits of data being hashed. 可以通过以太坊平台上的交易或合同执行的每项操作都需要一定数量的天然气, with operations that require more computational resources costing more gas than operations that require few computational resources.

天然气很重要的原因是它有助于确保支付适当的费用 by transactions submitted to the network. By requiring that a transaction pay for each operation it performs (or causes a contract to perform), we ensure that network doesn't become bogged down with performing a lot of intensive work that isn't valuable to anyone. This is a different strategy than the Bitcoin transaction fee, which is based only on the size in kilobytes of a transaction. Since Ethereum allows 任意复杂 computer code to be run, a short length of code can actually result in a lot of computational work being done. So 衡量直接完成的工作非常重要,而不是仅根据交易或合同的长度选择费用.

因此,如果天然气基本上是交易费,您如何支付?这是一个有点棘手的地方。虽然天然气是可以测量的东西的单位,但实际上并没有代币 for gas. That is, you can't own 1000 gas. Instead, gas exists only inside of the Ethereum virtual machine as a count of how much work is being performed. 说到实际付款 for the gas, the transaction fee is charged as a certain number of , the built-in token on the Ethereum network and the token with which miners are rewarded for producing blocks.

起初这可能看起来很奇怪。为什么操作不能直接在以太网中测量成本? The answer is that ether, like bitcoins, have a market price that can change rapidly! But the cost of computation doesn't go up or down just because the price of ether changes. So 将计算价格与以太币令牌的价格分开是有帮助的, so that the cost of an operation doesn't have to be changed every time the market moves.

这里的术语有点混乱。 EVM中的操作有气体成本, but gas itself also has a gas 价钱 measured in terms of ether. Every transaction specifies the gas 价钱 it is willing to pay in ether for each unit of gas, allowing the market to decide the relationship between the price of ether and the cost of computing operations (as measured in gas). 它是两者的组合,使用的总天然气乘以已支付的天然气价格,这导致交易支付的总费用.

尽管很棘手,但理解这种区别很重要,因为它会导致最初学习者关于以太坊交易最令人困惑的事情之一:您的交易耗尽与您的交易没有足够高的费用之间存在差异. If the 汽油价格 I set in my transaction is too low, no one will even bother to run my transaction in the first place. It will simply not be included in the blockchain by miners. But if I provide an acceptable gas 价钱, and then my transaction results in so much computational work that the combined 燃气费 go past the amount I attached as a fee, 气体算作“花费” and I don't get it back. The miner will stop processing the transaction, revert any changes it made, 但仍然将其作为“失败的交易”包含在区块链中,收取费用. This may seem harsh, but when you realise that the real work for the miner was in performing the computation, you can see that they will never get those resources back either. So 你支付他们所做的工作是公平的, even though your badly designed transaction ran out of gas.

提供太大的费用也不同于提供太多的以太。如果你设定一个非常高的汽油价格,你最终只会为少数几个操作支付大量的乙醚, just like setting a super high transaction fee in bitcoin. You'll definitely be prioritised to the front of the line, but your money is gone. If you provided a normal gas price, however, and just 如果您支付交易消耗的气体所需的以太多,则超出的金额将退还给您. Miners only charge you for the work that they actually do. 您可以将天然气价格视为矿工的小时工资,将天然气成本视为其工作时间表.

天然气有很多其他的微妙之处,但这应该给你基础知识!气体是使以太坊中的复杂计算“安全”以使网络工作的关键机制, because any programs that run out of control will only last as long as the money provided by the people who requested they be run. When the money stops, the miners stop working on it. And 您在程序中犯的错误只会影响付费使用它的人--the rest of the network can't suffer performance issues due to your error. They will simply get a big payday when the performance issues consume all of your ether! Without this critical technique, the idea of a general-purpose blockchain would have been completely impossible.

TL;博士:

  • 天然气是计算费用的方式
  • 尽管如此,这些费用仍以乙醚支付,这与天然气不同
  • 气体成本 is the amount of work that goes into something, like the number of hours of labour, whereas the gas 价钱 is like the hourly wage you pay for the work to be done. The combination of the two determines your total transaction fee.
  • 如果你的气体价钱 is too low, no one will process your transaction
  • 如果你的气体价钱 is fine but the gas 成本 of your transaction runs "over budget" the transaction fails but still goes into the blockchain, and you don't get the money back for the work that the labourers did.
  • 这确保没有任何东西永远运行,并且人们会小心他们运行的代码。它使矿工和用户免受恶劣代码的侵害!

12

以太坊中有关天然气的其他有用内容来自:HTTP://ET和doc S.org/恩/latest/ether.HTML#gas-安定-ether

气体和乙醚

天然气应该是网络资源/利用的固定成本。您希望发送交易的实际成本始终相同,因此您无法真正预期天然气将被发行,货币一般都是不稳定的。

因此,我们发布了其值应该变化的以太,但也实现了以太币的气价。如果以太网的价格上涨,以太币的天然气价格应下降,以保持天然气的实际成本相同。

天然气与其有多个相关条款:天然气价格,天然气成本,天然气限制和天然气费用。 Gas的原理是为以太坊网络上的交易或计算成本提供稳定的价值。

  • 气体成本是计算成本的静态值 气体,意图是气体的真正价值永远不会 变化,所以这个成本应该始终保持稳定。
  • 天然气价格是指另一种货币或代币的天然气成本 像以太一样。为了稳定天然气的价值,天然气价格是一个 浮动值,如果代币或货币的成本 波动,天然气价格变化保持相同的实际价值。该 天然气价格由用户数量的均衡价格决定 愿意花钱,并且愿意花多少处理节点 接受。
  • 气体限制是每个块可以使用的最大气体量,它 被认为是最大计算负荷,交易量或 块的块大小,矿工可以慢慢改变这个值 时间。
  • 燃气费实际上是运行a所需的燃气量 特定交易或计划(称为合约)。燃气费 可以使用块来表示计算负载,事务 块的体积或大小。燃气费支付给矿工(或 PoS的保税承包商)。

其他有用的链接:

HTTPS://呜呜呜.惹得地图.com/日/ether EU M/comments/271七点钟/惨_someone_explain_他和_concept_of_gas_in_ether EU M/ HTTPS://呜呜呜.惹得地图.com/日/ether EU M/comments/3妇女平日1/惨_someone_possibly_explain_他和_concept_of/ HTTPS://呜呜呜.惹得地图.com/日/ether EU M/comments/49过哦来3/惨_ether_不饿_used_阿斯_啊_currency_鳄梨5_ether_gas/


0

Gas是您在区块链上执行代码并将以太网转移到另一个地址时所支付的费用。对于以太坊虚拟机上的每条指令,您需要支付一定量的气体。一些说明很昂贵,有些说便宜。

如果在执行此函数调用时调用函数并且耗尽气体,则函数执行的所有更改都将被回滚,您将丢失所提供的所有气体。

每个指令需要气体而不是简单地执行任何功能的固定费用的原因是您可以编写具有无限循环的函数,部署此合同,然后调用该函数。如果你这样做,试图在下一个区块中包含函数调用的矿工将陷入无限循环。