Gas翻译为中文是燃料/汽油的意思。在以太坊(或其他网络),为了执行特定的操作(比如发送代币、存储、兑换代币)需要消耗一定的燃料,这个燃料我们称之为Gas。这就好比汽车要跑,就需要消耗汽油。在以太坊,要进行各种交互,就需要消耗Gas。举个例子:
Gas translates to Chinese as fuel/fuel. In Etheria (or other networks), certain fuel is required to perform certain operations (e.g. sending, storing, converting, etc.), which we call Gas. This is like running a car, consuming gasoline. In Etheria, for all kinds of interactions, it is necessary to consume Gas.
假设开车从A地到B地需要消耗10升汽油,每升的价格8元,那么,从A到B需要消耗的汽油费用:10*8=80(元)。
Assuming that driving from A to B would cost 10 litres of petrol at a price of $8 per litre, the cost of petrol from A to B would be 10*8 = 80 yuan.
同样,在以太坊网络,假设执行发送代币这个操作,需要消耗Gas的数量是21000个单位,每个单位Gas价格是100gwei。则执行这笔操需要支付的费用:21000*100=2100000gwei。
Similarly, on the Etheria network, it is assumed that the number of units that need to consume Gas is 21,000 and the price per unit is 100 gwei. The cost of carrying out this exercise is 21,000*100 = 210,000,000 gwei.
为什么需要Gas
Why do you need Gas?
我们都知道,在web2当中最重要的一个策略就是免费,来吸引流量实现变现。那么web3中的以太坊为什么不这么做呢?
We all know that one of the most important strategies in Web2 is free to attract the flow to make it real. So why not Etheria in Web3 do that?
收取gas费除了打赏奖励矿工等激励性质的作用之外,另一个作用就是防止恶意的攻击,假设没有gas费的设置,攻击者就可以发布无数死循环的合约,然后不断通过发送交易让节点运行,劫持全网的大量算力使得系统瘫痪。通过规定gas消耗量,以避免一些代码恶意的无限循环,导致资源浪费。当所有的gas消耗殆尽,就停止继续运转,好比汽车的汽油耗尽,车就停下来不走了,这就不至于无效者继续占坑。
In addition to the role of incentives such as reward for miners, the collection of gas fees has the effect of preventing malicious attacks, assuming that without gas fees, the attackers can issue numerous life-cycle contracts and continue to block the system by sending deals to allow nodes to operate, hijacking the entire network with a great deal of arithmetic. The waste of resources is caused by fixing gas consumption to avoid the vicious circle of some codes. When all gas is depleted, it stops functioning, as if the car was running out of gas, so that the car does not stop, so that the invalids do not continue to take advantage of the pit.
Gas Limit
什么是Gas Limit
What's Gas Limited?
在开头例子中,要计算从A地跑到B地汽油花了多少钱,除了要知道汽油价格(多少钱1升),还需要知道消耗的汽油量(用了多少升)。
In the initial example, the amount of gasoline spent from Land A to Ground B was calculated and, in addition to the price of petrol (how much 1 litre) it needed to be known how much petrol was consumed (how much litres were used).
同样,在以太坊网络,要计算某笔操作的成本(手续费),除了要知道Gas的价格,还要知道消耗的Gas的数量。
Similarly, in the Etheria network, the cost of a particular operation (the handling fee) is calculated by knowing, in addition to the price of Gas, the amount of Gas consumed.
Gas数量要消耗多少,由合约创建者设定,不同合约、不同类型的操作,消耗的gas数量不尽相同,操作越复杂需要消耗的gas越多,所以很难预先估计Ga的消耗量,为此采取的办法是,给定一个比实际消耗更高的限值,即Gas Limit,如果实际未消耗这么多,剩余部分将退回用户。
The extent to which the number of Gas is consumed is set by the contract creators, different contracts, different types of operations, different quantities of Gas, and the greater the complexity of the operation, the greater the consumption of Gas, making it difficult to estimate in advance the consumption of Ga by giving a higher limit than the actual consumption, that is, Gas Limit, and if this is not actually consumed, the remainder will be returned to the user.
在计算消耗的Gas数量时,钱包提供商比如metamask往往直接给出Gas Limit,如果实际消耗小于Gas Limit,剩余的返还。如果实际消耗超过Gas Limit,交易无法完成。
In calculating the amount of Gas consumed, wallet providers, such as Metamask, often give Gas Limit directly, if the actual consumption is less than Gas Limit, the remaining return. If the actual consumption exceeds Gas Limit, the transaction cannot be completed.
假设一笔以太坊网络转账需要消耗的Gas数量为21000,Gas Limit设置为50000,而实际只消耗21000,那么剩下的29000将自动返还。但如果实际消耗需要51000,而你只设置为50000,那么这笔交易将不会完成,消耗的50000也不会退回。
Assuming that the number of gasses to be consumed by the Taiwan network transfers is 21,000, and that Gas Limited is set at 50,000, while only 21,000 is actually spent, the remaining 29,000 will be returned automatically. If the actual consumption is 51,000, and you are set at 50,000, then the transaction will not be completed, and the 50,000 will not be returned.
所以,如果试图通过减小Gas Limit数值达到减少手续费的目的,可能会适得其反。不仅交易可能不成功,手续费照样扣。
Therefore, it may be counterproductive to attempt to reduce fees by reducing the value of Gas Limit. Not only may the transaction be unsuccessful, but the fees are deducted.
Gas Limit如何确定?
How can Gas Limited be sure?
Gas Limit的数值一般是钱包提供商默认自动给出的,通常不需要我们手动修改或者调整。
Gas Limit's values are generally given automatically by the wallet provider by default and usually do not require manual modifications or adjustments.
Gas price
什么是Gas price
What's Gas Price
Gas price,是指 Gas 的价格/单价,通常用Gwei来表示。
Gas price, which refers to the price/unit price of Gas, is usually expressed in Gwei.
Gas price如何确定
How does Gas Price determine
在2021年8月5日伦敦升级实施后,Gas price变成包含两部分的费用:基本费(base fee)和小费(Max priority fee)。
Following the implementation of the London upgrade on 5 August 2021, Gas Price became a two-part cost: base feed and tip.
「1.Base fee」
即基本费。每个区块都有一个作为底价的基本费,为了有资格被包含在一个区块中,Gas价格必须大于等于基本费。基本费用的确定方法,这里不展开,反正用户自己修改不了,由以太坊本身决定。
That is, the base fee. Each block has a base price, which, in order to be eligible for inclusion in a block, Gas must be greater than or equal to the base fee. The basic cost is determined in such a way as not to be started here, and the user itself cannot change it.
「2.Max priority fee」
即小费的意思。在滴滴打车的时候,遇到高峰时段,如果加10元、20元小费,可能你会优先叫到车。在以太坊网络Gas费的设计机制中,同样适用这个道理。你给小费,就可能优先成交。这里需要注意,基本费是根据网络拥堵情况实时变动的,可以通过网站查询基本费,而小费可以自己调整,一般调高不调低。
That means tipping. When you hit a drop-by, if you add $10 and $20, you might call the car first. The same thing applies in the design mechanism for the Taiwan network Gas fee. You give tips, you may pay them first. Here, it needs to be noted that the base fee changes in real time, depending on the congestion, and can search the base fee through the website, while the tip can be adjusted by itself, generally up and down.
「3.Max fee」
即每单位Gas的最高费用。最高费用是你愿意为每单位Gas支付的绝对最高金额,以使你的交易得到确认。在大多数情况下,你的实际交易费用将低于你预先指定的最高费用,你交易的最低Gas价格是当前的基本费用。然而,如果在你交易尚未完成时,基准费用增加了呢?那么,你的交易就有可能被卡住,或失败或被放弃。因此,为了在EIP-1559下实现可预测的交易结算,目前认为最好的做法是设置一个预期基本费用增加的最高费用。
That is, the maximum cost per unit Gas. The maximum cost is the absolute maximum that you are willing to pay for each unit Gas so that your transaction can be confirmed. In most cases, the actual transaction cost will be lower than the maximum fee you set in advance, and the lowest price for your transaction will be the current basic cost. But, if the base cost increases when your transaction is not completed, then your transaction may be stuck or lost or abandoned. So, in order to achieve a predictable settlement of the transaction under EIP-1559, it is now considered preferable to set a maximum cost of the anticipated basic cost increase.
上图是真实的交易费用。
The figure above is a true transaction cost.
注册有任何问题请添加 微信:MVIP619 拉你进入群
打开微信扫一扫
添加客服
进入交流群
发表评论