Advanced NFT — How do I set my gas?

lazymori.eth
Coinmonks
7 min readApr 12, 2022

--

If you have been following my previous series, you would have learnt about the basics of making money through NFTs. This series, I hope to go a little bit deeper to explore some of these small technical details that can give you an edge in trading in the NFT market.

Today, we will begin with gas. You might have thought to yourself why it costed some money to do an action in the blockchain be it to trade, buy, sell, mint, transfer. You might also hear tales of monstrous amount of gas fees being spent upon a failed transactions. We will uncover the technicalities so you know what to do as you begin to control gas on your own.

Gas is a component of a transaction in the Ethereum blockchain network. It’s like a fuel that allows a transaction to operate, just like a car that requires petrol to run.

Gas is the measurement of the amount of computational work that is required to execute specific operations on the Ethereum blockchain network.

Why does gas exists?

Think about it, why would the network calculate and specify an arbitrary computational work required or gas if the transactions are all free?

When we talk about computational work, we are essentially talking about the solving of cryptographic hashes or, simply put, solving puzzles. Cryptography, or puzzle solving, is a concept which is seen everywhere, most traditionally from keys and locks — putting the right key into the right lock to gain access to something/somewhere. Normally, we would not indicate the work required to find the right key to the right lock if you are going home. But you would indicate the work required if you are a locksmith helping someone to get into their house because that indication would point to a fee.

This means that gas is calculated for a reason and it is calculated for payment. In a car petrol top up, the amount of petrol pumped will be indicated so that we know how much to pay for each liter of petrol. Similarly, gas is indicated so that we know how much to pay per gas. In simple terms, this is called the gas fees. Gas fees are the monetary cost required to pay for the computational work to be done — often denoted in gwei or eth.

Do not confuse gas and gas fees. While they sound and look similar, they are different. Gas is simply the measurement of work, it’s defined in numbers and is usually automatically derived by the network and not recommended to be modified by users. Gas fees are the prices paid for the gas, it’s defined in gwei or eth, also derived by network but recommended to be modified by users.

Why does gas fees exist?

Gas fees are designed with security in mind for the Ethereum blockchain network. When a fee is required for every transaction, it prevents frivolous and hostile spamming. If no fees are imposed, sending malicious transactions will come at no cost, therefore the network will be full of malicious transactions which will make the network highly risky to use.

To combat potentially malicious transactions, the network imposed gas fee — that is why gas have to be calculated and gas fees have to be paid.

Who gets paid the gas fees?

Now, if Alice would want to transfer 1eth to Bob and it incurs a gas fee of 0.0001eth, the total amount deduct from Alice’s wallet will be 1.0001eth. But as Bob gets the 1eth, who gets the 0.0001eth?

Introducing miners, also known as mining nodes, also the ones who will claim the gas fee. One of their many roles is to mine transactions that are sent into the network. To mine a transaction is to process and execute a transaction. However, mining transactions are not so straightforward.

When transactions are first sent into the network, they don’t get processed immediately. They remain in a ‘pending stage’.

A quick segue: “pending stage” is also known as the mempool in the technical jargon. The mempool holds all pending transactions.

When a ‘new transactional period’ is ready, the entire Ethereum blockchain network will be made known of all the new pending transactions. These miners will copy all these pending transactions into their local system and systematically choose some transactions to be processed. By systematic, it means to prioritize and choose based on the highest gas fees. Miners are incentivized to prioritize the highest gas fee as they get to keep the fee — it’s like auction bidding.

A quick segue: “new transaction period” is also known as a block in the technical jargon. Each block contains transactions ready to be processed and subsequently processed transactions before joining the blockchain. Coincidentally, it is also the name behind blockchain — blocks of transactions chained together.

This mining concept is very important because it accounts for the transactional phenomenon that users will experience while using the Ethereum blockchain network. These phenomenon are perpetually pending transactions, failed transactions, dropped transactions, and cancelled transactions. We will run through these in the transactions article.

What does it mean for users?

As a user, the only thought process that matters is the one that revolves around cost. Every user wants to the most cost efficient solution.

Take for example, an NFT mint. When you have a waiting and potentially unsuccessful transaction, what should you do?

As we learn, gas are computational work required for a transaction. The gas will be high if it’s to run a very complex function like minting, and could be unreasonably high if the function is poorly written, which we will soon learn in the contracts article. You could do one of two things, to wait for the transaction to fail or to cancel it. Which is the more cost efficient action?

Failing transaction vs Cancelling transactions

Thankfully, one property of a cancelled transaction is to repurpose the function to a simple transfer function — meaning less computational work — thus reducing gas. However, cancelling a transaction will cost slightly more gas fees. Note the differences between gas and gas fees again!

A quick segue: Previously, we’ve obscured gas fee calculations. However, the formula is simplified to be gas fees = gas x gas price. The portion that is controlled by users are the gas price, which therefore controls the gas fees because gas is fixed depending on the function called by the transaction.

So, the only way that cancelling a transaction could be more cost effective is that the repurposing of the transaction function saves more money than the increased gas fees. Therefore, there’s only a question left — is the drop in gas more the increase in gas fees?

DevCandy

This part is for aspiring developers. Up till this point, we’ve explained gas and gas fees simply, that was how gas used to work in the past. It was easier to understand, and it builds a fairly strong foundation to understand how gas works now because it’s 70% similar. We see major wallet providers are compliant to the new gas changes because it makes gas more predictable and has fine-granularity of gas control especially during peak period.

On 5th August 2021, the Ethereum London hard fork, also known as EIP1559, went into effect.

Previously, we understand gas fees calculation simply as:

gas fees = gas x gas price

Now, instead of gas price, it’s broken into 3 new values:

gas fees = gas x (base fee + priority fee)

As a user, you will not have to worry about base fee because there are no way you can see or adjust it. However, you could adjust priority fees.

Remember how higher gas fees used to incentivize miners to mine the transaction? Now it’s replaced with priority fee. The miner will prioritize according to priority fees.

There is also a new limit created called max fee per gas where we calculate the maximum amount of price we are willing to pay per gas:

max fee per gas = (2 x base fee) + priority fee

Max fee per gas can be adjusted to set an upper bound as to what is the maximum price you are willing to pay per gas. Only in a low traffic period will your max fees help you to save gas fee. In a high traffic period, due to the high base fees, if miners do not mine your transactions due to low priority fees, it will wait for the next block and base fees will likely increase.

Here’s a flow chart to help understand the dynamics between priority fee and max fee per gas.

Logically, no one in the right mind will set a higher priority fee than the max fee per gas because it will never succeed, but it can still be done.

A quick segue: If you want to learn how base fee is calculated, you can find more information here.

Concluding Thoughts

At the heart of the choices, it’s between monstrously quick math and understanding of your transaction’s data. Making a rough estimation could usually help you make the decision thus saving you some gas.

It’s worth noting however, that once an extremely high gas price is set by you in the scenario of competing in a public NFT mint, whether it was failed or cancelled, it will be costly. So, be careful!

Join Coinmonks Telegram Channel and Youtube Channel learn about crypto trading and investing

Also, Read

--

--

lazymori.eth
Coinmonks

just a man trying to understand this space of nfts, cryptocurrencies, and web3 technologies.