If you like this content, please subscribe and join 1000+ readers in our newsletter around the NFT, crypto, and tech space!
If you've been around the NFT, crypto, or blockchain space, a term you've probably heard a lot is gas. Most of the time, this is on the Ethereum blockchain. But what exactly is gas? Sure, you can just think of gas as a transaction fee that's required for interacting with the Ethereum blockchain, but I think its very beneficial to deep-dive into gas.
Why? With the current gas wars, understanding how gas is calculated and used will help you optimize your gas fees for mints/transactions. Additionally, learning about gas will help you understand why gas fees are currently very high on Ethereum, what alternatives there are, and why people are waiting for Ethereum 2.0.
Before we dive in, there's some terminology such as transactions and blocks used throughout the article. I recommend reading this guide on blockchains if you are unfamiliar with them!
Why is there gas?
Let's first talk about why gas is even required in Ethereum. Per Ethereum's official docs:
By requiring a fee for every computation executed on the network, we prevent bad actors from spamming the network. In order to avoid accidental or hostile infinite loops or other computational wastage in code, each transaction is required to set a limit to how many computational steps of code execution it can use. The fundamental unit of computation is "gas".
What does this mean exactly? In short, every operation on Ethereum requires gas which makes sure developers optimize their code and prevent spam from bots.
How To Calculate Gas
On August, 5, 2021, the London Upgrade was implemented into Ethereum and gas prices became much more complex but predictable. This introduced a lot of new terminology and settings that are important to understand.
Prior to EIP-1559, there was only one price to pay attention to, the gas price. Now, there are a few terms that we need to know:
- Base Fees, this is determined by the network and previous block size and is subsequently burned. This can either increase or decrease by 12.5% depending on size of the last block.
- Max Priority Fees, which incentivize/tip the miner and allow your transaction to be executed ahead of others. While this is optional, there is usually a minimum 2.0 GWEI tip required.
- Max Fees, which is the max limit you are willing to pay for a transaction. This must be greater than the base fee + priority fee and you will be refunded the difference later. One thing to consider is that the base fee can increase while your transaction is pending, so setting a higher max fee might be necessary if you want to guarantee your transaction to go through.
If these terms are confusing, we'll go over a practical scenario on how to use and set these when the network is congested.
One of the most popular wallets used is MetaMask. Let's go over how to adjust the settings in MetaMask. By default, MetaMask automatically sets the priority fee in the general settings to low, medium, or high speeds when editing gas fees.
One way to change this is by going to your Account Settings -> Advanced -> Turn On Advanced Gas Controls. This will allow you to edit your gas as the max priority fee and max fee level.
Most of the time you won't need to edit your gas fee from the recommended minimum, but when gas wars occur while minting NFTs, it's important to understand how to almost guarantee yourself a successful transaction. There are a few methods outlined beautifully by @thedigitalvee that I have summarized here.
Always raise both the priority fee and max fee
Before we get to the methodology of actually setting the best fields, we have to understand why we must raise both the priority fee and max fee.
Let's first look at if we only raise the priority fee. As we went over before, the priority fee is a tip that will incentivize the miner. So what's the issue? The issue is that the base fee could change, especially at a full capacity network. Since the max fee must be greater than both the base fee and the priority fee, if this remains unchanged and the base fee increases, then the priority fee must decrease.
So what if we just raise the max fee. This would definitely account for the base fee increase and variability, but our miner tip is capped at the default 2.0 GWEI, which is nowhere near enough to mint popular NFTs before they sell out.
The solution? Both of these must be raised at the same time to guarantee that we account for base fee variability and miner incentives. But how exactly do we calculate how much to raise the priority fee and max fee?
Set a high max fee and priority fee to the same value
If we really want our transaction to go through, we can set a high max fee and high priority fee to the same value. Why? The high max fee means that we will cover the variability of the base fee and the leftover difference will be the miner's tip (priority fee).
This basically guarantees that we have give the highest tip to the miner that we are willing to pay (max fee - base fee).
We can refer to the image above where @thedigitalvee used this technique on the MAYC drop back in August. He set both the priority and max fee to 700 GWEI. Given that the base fee was 365, he paid 335 GWEI in priority fees (700 - 365).
The conversion from GWEI to ETH is total gas in GWEI * Gas Units used * 10^-9 ETH/per GWEI. Plugging in the numbers looks something like 700 * 176654 * 0.000000001 = 0.123658 ETH which is how much was charged in this transaction.
The above method accounts for the unexpected variability of the base fee. Since we are giving the entire difference of the max fee and base fee as tip, there is a strong chance that this method would be overpaying the miners. Blocknative has its own recommendation of setting the max fee.
Feel free to read more in their guide here, but to summarize, their formula guarantees that the transaction would go through for at least 6 consecutive blocks. Is this enough when the network is busy and thousands of people are overpaying? Probably not. But this gives a much more cost-friendly way of minting NFTs and a guarantee of at least 6 blocks before you are accepted.
If you want to find out the base fee and priority fees to pay using this method, definitely check out their gas estimator!
If you like this content, please share this article and support us by joining our free newsletter where we will consistently share trends, tips, and stories in the NFT, crypto, and tech space!