什么是燃气?
燃气是智能合约区块链(最著名的是以太坊)使用的一个测量单位,用于量化交易或合约操作所需的计算工作量。网络根据每个操作所消耗的资源定价,而不是对每个操作收取固定费用——例如发送代币、在去中心化交易所(DEX)上交换或铸造非同质化代币(NFT)。用户支付燃气费用以让验证者将他们的交易包含在区块中,这笔费用也有助于保护网络免受垃圾邮件的影响。燃气是如何工作的?从高层次来看,燃气将“计算工作”转化为可预测的账单。区块链可以执行的每个操作都有一个相关的燃气成本。简单的操作(如转移代币)通常消耗的燃气少于复杂的操作(如与多步骤的去中心化金融协议交互)。当你提交交易时,你实际上是在说:(1)你愿意允许多少工作,以及(2)你愿意为每单位工作支付多少费用。大多数网络用两个关键输入来表示这一点:1. 燃气限制:你的交易允许消耗的最大燃气单位。2. 燃气价格(或费用率):你为每单位燃气支付的费用,通常以链的本地代币计价。总费用大致为:总燃气费用 = 使用的燃气 × 燃气价格如果你的交易耗尽燃气(意味着它需要的燃气超过了你的燃气限制),网络将停止执行。这是一个安全特性:它防止有缺陷或恶意的代码消耗无限资源。在许多智能合约环境中,执行失败仍然可能产生费用,因为验证者在尝试处理时消耗了资源。一个有用的类比是出租车计价器。使用的燃气就像实际行驶的距离/时间,而燃气价格就像每英里的费用。在高峰时段(网络拥堵),费率可能会上升,因为区块空间稀缺,用户竞争更早被包含。
燃气在实践中
每当你进行超过“读取”区块链数据的操作时,燃气就会出现。例如,在以太坊和其他EVM兼容链上,诸如在自动化做市商(AMM)上交换代币、提供流动性、在借贷协议上借款或部署智能合约等操作都需要燃气。即使两个交易发送相同的代币数量,它们的燃气使用也可能因交易在后台的操作而有所不同。
钱包和去中心化应用程序(dApps)通常会为你估算燃气。当你批准代币支出时,该批准是一个单独的链上交易,具有自己的燃气成本。当你稍后执行交换时,那又是另一个交易,具有另一个燃气成本。理解这一点有助于用户避免意外,特别是在多个步骤常见的去中心化金融工作流程中。为什么燃气很重要燃气是保持智能合约网络可用和安全的主要机制之一。通过将计算和存储附加上真实的成本,燃气抑制了垃圾邮件和拒绝服务行为,否则这些行为会淹没网络。它还为验证者处理交易和维护共识创造了经济激励。燃气还影响用户体验和应用设计。开发者优化智能合约以减少燃气使用,因为更便宜的执行可以使应用更具竞争力和可访问性。对于用户来说,燃气决定了交易确认的速度以及与链上服务交互的费用。如果没有燃气(或等效的资源定价系统),区块链将难以公平和可靠地分配有限的区块空间。[@portabletext/react] Unknown block type "span", specify a component for it in the `components.types` prop
[@portabletext/react] Unknown block type "span", specify a component for it in the `components.types` prop[@portabletext/react] Unknown block type "span", specify a component for it in the `components.types` prop
[@portabletext/react] Unknown block type "span", specify a component for it in the `components.types` prop
[@portabletext/react] Unknown block type "span", specify a component for it in the `components.types` prop[@portabletext/react] Unknown block type "span", specify a component for it in the `components.types` prop[@portabletext/react] Unknown block type "span", specify a component for it in the `components.types` prop[@portabletext/react] Unknown block type "span", specify a component for it in the `components.types` prop[@portabletext/react] Unknown block type "span", specify a component for it in the `components.types` prop
[@portabletext/react] Unknown block type "span", specify a component for it in the `components.types` prop
[@portabletext/react] Unknown block type "span", specify a component for it in the `components.types` prop[@portabletext/react] Unknown block type "span", specify a component for it in the `components.types` prop[@portabletext/react] Unknown block type "span", specify a component for it in the `components.types` prop[@portabletext/react] Unknown block type "span", specify a component for it in the `components.types` prop[@portabletext/react] Unknown block type "span", specify a component for it in the `components.types` prop[@portabletext/react] Unknown block type "span", specify a component for it in the `components.types` prop[@portabletext/react] Unknown block type "span", specify a component for it in the `components.types` prop
[@portabletext/react] Unknown block type "span", specify a component for it in the `components.types` prop
[@portabletext/react] Unknown block type "span", specify a component for it in the `components.types` prop
[@portabletext/react] Unknown block type "span", specify a component for it in the `components.types` prop
[@portabletext/react] Unknown block type "span", specify a component for it in the `components.types` prop