What is "GAS" or blockchain fees in the Ethereum ecosystem.
1. Introduction.
"Gas" is a unit of measurement that indicates the amount of computational effort required to perform specific operations on the Ethereum blockchain ecosystem . Since every transaction in Ethereum requires computing resources to execute, it is logical that this same technological operation requires a fee. Therefore, the term “Gas” refers to the fee required to successfully complete an Ethereum transaction.
Gas fees are paid in Ethereum's native currency, Ether (ETH) . The prices of "Gas" fees are denoted in "gwei" , which itself is a denomination of ETH - each "gwei" is equal to 0.000000001 ETH (10-9 ETH). For example, instead of saying that a "Gas" fee costs you 0.000000001 ether, you can say that "Gas" fees cost you 1 gwei. The word "gwei" itself means "giga-wei" and is equal to 1,000,000,000 "gwei". The "gwei" itself (named after Wei Dai, the creator of b-money) is the smallest unit of ETH .
2. Charges for "Gas" before the update in London.
The way transaction fees are calculated on the Ethereum network changed with the August 2021 London Update. Here's a quick summary of how things worked prior to this point:
Let's say Annie had to pay Boyan 1 ETH. In the transaction, the limit of "Gas" charges is 21,000 units, and the price of each individual "Gas" charge is 200 "gwei".
The total fee before would be: 21,000 x 200 = 4,200,000 "gwei" or 0.0042 ETH
3. Calculation of Gas charges after the update in London.
Let's give the following example - let's say that George needs to pay Nikolai 1 ETH. In the transaction, the limit of "Gas" charges is 21,000 units and the base charge is 10 "gwei". Nikolai includes a tip of 2 "gwei" in the block(validator).
This logic indicates that the total fee will be: units of gas used x (base fee + priority fee), where the base fee is a value set by the protocol and the priority fee is a value set by the user as a tip to the validator.
The formula will look like this : 21,000 x (10 + 2) = 252,000 "gwei" or 0.000252 ETH.
When Georgi sends the money, the amount of 1.000252 ETH will be withdrawn from his account. 1.0000 ETH will be transferred to Nikolai's account. The validator receives a tip of 0.000042 ETH. The base fee of 0.00021 ETH has been burned.
In addition, George can also set a maximum fee (maxFeePerGas) for the transaction. The difference between the maximum fee and the actual fee is refunded to George, i.e. refund = maximum fee - (base fee + priority fee). Georgi can set a maximum amount to pay to complete the transaction and not worry about paying "above" the base fee when the transaction is completed.
4. Features concerning the size of the block .
Before the London update, the Ethereum ecosystem had fixed size blocks. At times of high demand on the network, these units operated at full capacity. As a result, users often had to wait for high demand to subside in order to join a "favorable" block, leading to a poor user experience.
With the London update , variable size blocks were introduced to the Ethereum ecosystem . Each block has a target size of 15 million “Gas”, with the specific value of the blocks increasing or decreasing according to network demand, until reaching the limit of 30 million “Gas” (or 2 times the target block size). The protocol achieves an equilibrium block size of 15 million on average through the “scaling” process. This means that if the block size is larger than the target block size, the protocol will increase the base fee for the next block. Similarly, the protocol will reduce the base fee if the block size is smaller than the target block size. The amount by which the base "Gas" fee is adjusted is proportional to how far the current block size is from the target.
5. What is base " Gas" fee ("baseFeePerGas")?
Each block has a base fee that acts as a reserve price. In order for a subsequent block to be included, the offered price of "Gas" takasa must be at least equal to the base takasa. The base fee is calculated independently of the current block, being determined by the logic of the fee of previous blocks - this makes "Gas" transaction fees more predictable for users. When the block is completed, this base charge is "burned", taking it out of circulation.
The base fee is calculated by a formula that compares the previous block size (the amount of “Gas” used for all transactions) to the target size. The base fee will increase by a maximum of 12.5% per block if the target block size is exceeded. This exponential growth makes it economically unviable to maintain a high block size indefinitely.
Here is an example formula including block number, Gas charge increase and current base charge:
Block 1; increase 15M - 0%; base fee - 100 "gwei";
Block 2; increase 30M - 0%; base fee - 100 "gwei";
Block 3; increase 30M – 12.5%; base fee - 112.5 "gwei";
Block 4; increase 30M – 12.5%; base fee - 126.6 "gwei";
Block 5; increase 30M – 12.5%; base fee - 142.4 "gwei";
Block 6; increase 30M – 12.5%; base fee - 160.2 "gwei";
Block 7; increase 30M – 12.5%; base fee - 180.2 "gwei";
Block 8; increase 30M – 12.5%; base fee - 202.7 "gwei".
Compared to the "Gas" fee market before the London update, the commented change in the mechanism of transaction fees today leads to more reliable forecasting. Following the logic of the table above, to create a transaction in block #9, the wallet will inform the user with certainty that the maximum base fee that will be added to the next block will be calculated as follows: current base fee 12.5% x 202.7 "gwei" = 228.1 "gwei".
It is important to note in this context that we are unlikely to witness sustained spikes in full blocks (the final, completed block in a chain of successively verified ones) due to the rate at which the base fee increases, proceeding to the formation of a full block .
It is also important to note that we are unlikely to see sustained spikes in full blocks due to the rate at which the base fee increases when processing a full block.
6. Priority fee ("gratuity").
Before the London update, "miners" [1] received the total "Gas" fee from each transaction included in a given block.
With the principle of "burning" the base fee when a block is completed, the London update introduced a so-called "priority fee" (or "tip") to incentivize miners to include a transaction in a block. Without "tips", miners would find it economically more profitable to mine empty blocks, as they would receive the same reward per block. Under normal conditions, a small "tip" provides miners with a minimal incentive to include a transaction. Transactions that need to be executed preferentially, before other transactions in the same block, will require a higher tip to try to get ahead of competing transactions. As it becomes clear, all this leads to building incentives in the blockchain ecosystem, with the aim of its dynamic development.
7. What is "maxFeePerGas".
To complete a transaction on the network, users can specify a maximum limit that they are willing to pay for their particular transaction to be completed. This optional parameter is known as "maxFeePerGas". For a transaction to go through, the maximum fee must exceed the sum of the base fee and tip. Thus, the difference between the maximum fee and the sum of the basic fee and tip is reimbursed ex post facto to the sender of the transaction.
8. Calculation of fees .
One of the main benefits of the update from London 2021. is that the user experience when determining transaction fees has been improved. What does this mean? For wallets that technically support the upgrade, instead of explicitly stating how much a user is willing to pay to get their transaction through, wallet providers will automatically set a recommended transaction fee (base fee + recommended priority fee) to reduce complexity , with which users are charged. This happens via the EIP-1559 protocol.
The implementation of EIP-1559 in the London update made the transaction charging mechanism more complex than the previously used protocol for the price of "Gas" charges, but it has the advantage of making said charges more predictable, resulting in a more efficient gas market. transaction fees. In this way, users can submit transactions with a maxFeePerGas corresponding to how much they are willing to pay to complete the transaction, knowing that they will not pay more than the market price of the "Gas" fee (baseFeePerGas) , and get back any additional amount , less their tip.
9. Why do “Gas” charges exist?
In short, gas fees help keep the Ethereum ecosystem secure. When we charge a fee for every computation performed on the network, we prevent the network from being "smashed" (corrupted) by unscrupulous actors. To avoid random or hostile infinite loops or other computational waste in the code, each transaction is required to set a limit on how many computational steps of code execution it can use. The fundamental unit of calculation for the commented charges is "Gas".
Although the transaction includes a limit, any "Gas" not used in the transaction is returned to the user (ie the maximum charge - (base charge + tip) is returned).
10. What is the " Gas" limit?
The term "Gas limit" refers to the maximum amount of "Gas" you are willing to spend on a given transaction. More complex transactions involving smart contracts require more computational work, require a higher "Gas" limit than a simple payment. A standard ETH transfer requires a gas limit of 21,000 "Gas" units.
For example, if you set a gas limit of 50,000 units for a simple ETH transfer, the blockchain ledger (the so-called "ledger" or EVM) will consume 21,000 units and you will receive back the remaining 29,000 units. However, if you set too little gas, for example a limit of 20,000 "Gas" units for a simple ETH transfer, the EVM will consume your 20,000 "Gas" units trying to complete the transaction, but it will not complete. The EVM then restores all changes, but since the miner has already done work worth 20 thousand gas units, this "Gas" is spent ("burnt").
11. Why can "Gas" charges become low?
The high gas fees are due to the popularity of Ethereum. Performing any operation on Ethereum requires consuming "Gas", and the space for "Gas" is limited for each block. Fees include computing, storing or manipulating data, or transferring tokens by consuming varying amounts of "Gas" units. As dapp functionality becomes more complex, the number of operations that a single smart contract performs also increases, meaning that each transaction takes up more space than the limited block size. If there is too much demand, users must offer a higher tip amount to try to overtake other users' transactions. A higher tip can increase the likelihood of your transaction making it to the next block.
The price of "Gas" alone does not determine how much we have to pay for a given transaction. To calculate the transaction fee, we need to multiply the "Gas" used by the "Gas" base fee, which is measured in "gwei".
12. Initiatives to reduce "Gas" fees.
Ethereum's scalability improvements should eventually solve some of the gas fee issues, which in turn will allow the platform to process thousands of transactions per second and scale globally.
The scaling of the so-called “Lear 2” (the newest “Gas” protocol in the Ethereum ecosystem) is a major initiative to significantly improve Gas costs, user experience and scalability. The most popular "Lear 2" networks on the market are Optimism, Arbitrum, dYdX, Starkware and Loopring. As of November 2022 and until now, the Optimism project dominates the market with almost 50% share, followed by Arbitrum with around 30% of the market and dYdX, which has a small share of it.
13 . Strategies to reduce "Gas" costs.
If you want to reduce the "Gas" costs of your project in the Ethereum ecosystem, you can program a so-called "tip" to show the level of priority fees of your transaction in the ledger. So "miners" will "work" for you and execute transactions that offer a higher "tip" for "Gas" as they seek to keep the priority fees you pay and will be less inclined to execute transactions with lower set such fees. All this is programmed in the code according to the specified, commented logic, thus the protocol respects the logic of the "tip".
Author: Mr.Atanas Kostov - blockchain attorney
[1] The participants in the process of checking and adding blocks in a blockchain book (from the English "ledger"), as well as adding crypto tokens in circulation, using the so-called "consensus mechanism" (from the English Proof of work ”) to prove the operation of the relevant block;