Most Effective Methods of Optimizing Gas When Minting NFTs on Ethereum

Written by anton-dzyatkovskii | Published 2022/06/14
Tech Story Tags: web3 | tatum_io | web3-writing-contest | ethereum | nfts | nft-minting | ethereum-top-story | ethereum-blockchain

TLDRNFT collections are bundles of unique digital objects founded on a single principle and have become enormously popular in the crypto market of late. The variety of blockchains that NFT. collections have been launched on in 2022 has noticeably increased. But despite its advantages and enormous popularity, this. blockchain is not without its drawbacks, the main one being its high gas prices. In this article, I look at the most effective strategies for reducing the cost of gas when minting NFTs. We will talk about how to reduce the gas for minting.via the TL;DR App

NFT collections are bundles of unique digital objects founded on a single principle and have become enormously popular in the crypto market of late. The variety of blockchains that NFT collections have been launched on in 2022 has noticeably increased, but Ethereum remains the most popular by far. 
However, despite its advantages and enormous popularity, this blockchain is not without its drawbacks, the main one being its high gas prices. In this article, I look at the most effective strategies for reducing the cost of gas when minting NFTs. 

Ethereum’s popularity

Even though the cryptocurrency market at large has been in a multi-month downtrend since November 2021, enthusiasm for NFT activities remains strong. According to data collected by the analytical platform IntoTheBlock, which specializes in blockchain analysis, the number of NFT commission charges on the Ethereum network has increased by more than 100 percent in 2022. If a year ago the network had approx. 15,500 collections available, now it has more than 80,000 collections.
Despite the development and growing popularity of other blockchains such as Solana, Polygon and Avalanche, Ethereum continues to top the leaderboard of blockchains by the number of deployed NFTs, according to the latest data from CryptoSlam:
Meanwhile, the total NFT trading volume has grown significantly over the past year, increasing by almost 90 times from $622 million per day (a year ago) to about $54.58 billion per day today.
The number of Ethereum addresses with at least one NFT has significantly increased since September 2020. Only 1.4% of wallets had one or more NFTs a year ago and now that number has grown to 4.64%. Needless to say, the NFT market is booming, despite certain concerns.
Ethereum offers convenient solutions for launching applications and NFT collections, raising funds and creating smart contracts. All of this is blockchain-based. The system uses its own programming language and its own means of payment and settlement - Ether (ETH).
The increase in ICO projects in 2017 was due to the possibility of being able to launch a new coin or new technology faster than before. First of all, Ethereum streamlined the transaction process, thus reducing its cost. This made Ethereum an easier platform for launching new projects, which is why it became so popular.
Ethereum is famous for a large number of big NFT projects whose collections have gained popularity all around the world. Among these are:
  • CryptoPunks - the most popular and first NFT collection, now legendary in the NFT market. 
  • Bored Ape Yacht Club - one of the most successful collections on the NFT market, consisting of 10,000 monkeys with unique traits, including clothing, hats and facial expressions.
  • Azuki - another popular Ethereum-based NFT project. One of the factors that makes Azuki stand out the most is its Anime-inspired design, conquering holders all over the world.
Of course, this is just a sample of Ethereum-based NFT projects that have gained enormous fame and achieved record breaking sales. So why do so many NFT projects choose the Ethereum blockchain to release their collections on? Let's take a closer look at the main advantages of the network and then its disadvantages.

Ethereum’s advantages

Security and openness
The Ethereum blockchain is a database of information that’s designed to grow. Once information is added, the data cannot be changed or erased. Ethereum contains millions of transactions that are grouped into blocks along with smart contracts. The blocks form a sequence – a complete history of every transaction ever executed on Ethereum.
Everything that happens on the Ethereum network is recorded in real time. A copy of each transaction is distributed throughout the network. Each node in the network stores a copy of this history.
Everything that happens inside the blockchain obeys complex mathematical laws that provide reliable protection.
Smart contracts
Ethereum has a high level of functionality and provides the framework for smart contracts. Contracts on the Ethereum network support transactions and compliance with agreements in the digital environment.
At the moment, the main scope of application for Ethereum’s smart contracts is the raising of funds during Initial Coin Offerings and ensuring the smooth operation of thousands of dApp applications.
Basically, it is the network’s great diversity of smart contracts that allow developers to define the total supply of the collection, the amount of NFTs that can be minted by each user, the costs of minting and whether there will be whitelisted users or not. 
Aside from that, developers are able to modify the code within smart contacts in order to reduce the gas for minting, which we will talk about later on.

Ethereum’s disadvantages

Low bandwidth
The principle underlying the operation of Ethereum is old and its bandwidth can only handle 14 TPS. That is, it takes about 17 seconds to generate a new block in the blockchain. Information about a transaction appears within 1-1.5 minutes. This is too long for the proper running of many financial applications.
The reason for the low speed is that every blockchain block checks the transaction as it takes place. The bigger the "chain", the more time it takes to verify it.
The cost of commission
Ethereum, when used as a system for blockchain applications, charges a fee for actions executed via these applications, which is called gas. For any action, including the creation and publication of an NFT, a commission must be paid on the blockchain. To carry out actions in the Ethereum blockchain, users must pay a certain amount of gas (charged solely as payment for actions) and the exact cost is tied to the Ether coin.
To a greater extent, the cost of this commission depends on the miners. When the network is overloaded, the cost of gas increases and when activity is low, it falls back down again.
The amount of gas a user chooses to pay affects the transaction execution speed — users can generally opt to pay the present moment average gas price or they can choose to pay above/below the average price. The more they pay in gas, the faster their transaction will be completed. But if the price is set too low, there is a danger that the transaction freezes or takes a long time to execute. Another danger with smart contracts is the possibility that not enough gas has been offered for the execution of a transaction.
So in addition to the price of the NFT itself, you will need to pay gas. Depending on the network load, this may cost you 0.03 ETH to 0.07 ETH.
However, before resigning to how painful this all sounds, there are ways around this problem. We have a few strategies for optimizing gas costs that we are glad to share with you.

Azuki smart contract

For clarity, we’ll use concrete examples to demonstrate how gas costs can be kept to a minimum. The Azuki smart contract (ERC-721A) allows users to mint several tokens for close to the cost of minting one. 
In comparison to OpenZeppelin’s ERC-721 Enumerable smart contract, Azuki offers excellent savings, where users can save a significant sum of money. For instance, minting one token using the Enumerable standard comes to $162.55, but when using Azuki’s version, users would only pay $82.03 (assuming a gas fee of 300 gwei and valuing ETH at $3,500 USD). 
What is more interesting is that if one was to mint five NFTs via Enumerable, the cost rises to an astronomical $740.30 and Azuki’s ERC-721A manages to keep to an affordable fee of $89.47.
But how are the developers of Azuki’s NFT collections able to achieve such an outstanding level of optimization? Let’s go through the primary steps they underwent when developing their smart contract. 
Changing the frequency of user balance updates
To start with, their technicians decided to update NFT holders’ balance once per batch of minted NFTs instead of every time an NFT is minted. For example, if someone already owns 3 tokens and has a desire to buy 2 more, the Ethereum network charges an update fee every time the stored value changes.
Azuki’s developers have chosen to track the quantity of tokens each user owns and update users’ holdings (to continue with our example) from 2 directly to 5 in one update, since making 3 separate updates for each token leads to higher minting costs.  
Getting rid of duplicate storage 
In addition to this, Azuki has removed duplicate information from ERC-721 Enumerable because it stores an excessive amount of metadata on each NFT, which costs a substantial amount for writing functions. Even though this approach enables read functions to be optimized, it is not the most rational solution, since users are much less likely to pay for read functions. 

Alpha Girl Club smart contact 

Next, we have a project called Alpha Girl Club that boasts low gas fees using good old Ethereum, whose range is between $40 - $55 per NFT.
The smart contract code created for these NFT collections is heavily optimized by this project by leaving out the whitelisting mechanism altogether, as it puts a significant strain on the entire system. Instead, the project has opted to go with hashing checks, which are executed off-chain. 
Furthermore, Alpha Girl Club’s smart contract has cleaned up the standard Enumerable functions of most ERC-721 NFTs. The Enumerable smart contract obtains various metrics, including numerous iterations of certain counts and balances. These functions allow the creators to publish its full list of NFTs and go public with the total supply of a collection and number of already minted tokens. 
The team felt it was worth the sacrifice to put this information on Etherscan for the sake of lower gas prices. However, criticizing the winners can come across as a little judgemental.

Final thoughts

In conclusion, it is clear that modifying parts of a smart contract’s code can lead to a reduction in the cost of minting NFTs but the ramification of doing so is the loss of functionality in the final product.  
Technological progress does not stand still so we as users of the market can reasonably expect some breakthrough solution to come along one day and reduce the price of minting on the Ethereum chain, while keeping all this type of token’s functions intact.


Written by anton-dzyatkovskii | CEO and co-founder of Platinum Software Development Company. Blockchain enthusiast, blogger.
Published by HackerNoon on 2022/06/14