Skip to content
0%

ERC721 vs. ERC721A: batch minting NFTs

Author: Albert Hu

Last updated: March 16, 20228 min read

As many NFT creators know, deploying a smart contract to Ethereum mainnet can be insanely expensive.

However, smart contract deployment costs are not the only cost blockchain engineers and NFT teams need to consider. Creating a successful NFT collection or collectible avatar project includes building a community and making it easy for users to mint,** trade**, and** use** their NFTs.

Let’s learn about a powerful NFT smart contract optimization that can help your community save gas fees on NFT minting costs:

Implementing batch minting with the ERC721A contract!

What is ERC721A?

On Jan 6th, the Azuki NFT development team publicly announced ERC721A, a new implementation of the ERC721 NFT standard that explores batch minting:

Azuki team introducing ERC721A Implementation
Azuki team introducing ERC721A Implementation

In their blog post explaining the ERC721A smart contract implementation, @locationtba and @2pmflow show estimates of how much gas can be saved when batch minting via the most commonly used NFT smart contract starter code, OpenZeppelin’s ERC721Enumerable contract, vs. batch minting NFTs using the new Azuki ERC721A contract:

NUMBER MINTEDGAS USED (ENUMERABLE)GAS USED (ERC721A)GAS SAVED

Mint 1

154,814

76,690

78,124

Mint 2

270,339

78,819

191,520

Mint 3

384,864

80,948

303,916

Mint 4

501,389

83,077

418,312

Mint 5

616,914

85,206

531,708

This table shows how the gas used for ERC721A for an increasing number of mints scales at a much smaller constant factor.

The gas cost to mint NFTs increases by:

  • ~2k gas per extra mint using the Azuki ERC721A contract
  • ~115k gas per extra mint using the OpenZeppelin ERC721Enumerable contract

This result is actually AMAZING!

For the price of minting one single token via the ERC721Enumerable contract, a user can instead mint up to 5 tokens (or more, potentially) via the ERC721A contract.

Who wouldn’t want users to save up to 80% on their mints?

Here’s the best part:

Not only do the NFT mint prices become cheaper for individual transactions, but there would also be less network congestion and smaller gas price spikes affecting the Ethereum network during popular collection drops.

Pretty cool stuff.

Verifying the gas savings for minting multiple NFTs

I wanted to check the work myself, so I implemented two basic NFT contracts that create NFTs:

  1. One smart contract that mints using ERC721Enumerable, and
  2. One smart contract that mints using ERC721A

Next, I called the mint function on each one and logged the gas costs for each transaction.

Here are my results:

You can find the code for these tests in this GitHub repo: demo-erc721a

The gas costs to make multiple NFTS here are slightly different than the ones shown in the Azuki blog post, but they are close, and the increase in gas fees from one mint, two mints, and multiple mints checks out.

We’ve validated the gas savings for batch minting NFTs! ✅

How does the ERC721A smart contract save gas fees with batch minting?

ERC721A makes some assumptions that influence its smart contract design:

  1. Token IDs should always increment consecutively starting from 0. Most NFT projects already do this, and Azuki is explicit about it in their assumptions.
  2. Reducing the gas costs of minting NFTs is more important than optimizing any other ERC721 call. Mints are when Ethereum network congestion happens, and they’re also users’ first impressions of an NFT collection. The easier the mint, the better the reputation.

With these assumptions in place, ERC721A makes the following contract optimizations:

  1. Reduce wasted storage of token metadata.
  2. Limit ownership state updates to only once per batch mint, instead of once per minted NFT.

We’ll take a look at how these optimizations are done, but before that we should understand what kinds of transactions cost the most gas fees.

Reducing the work required to send write transactions saves users gas

There are generally two kinds of transactions on the blockchain: writes and reads.

Writes happen when we modify or update blockchain state (e.g. sending money, writing a message, trading an NFT).

Reads happen when we request existing data to look at it.

Users always pay more gas fees for write functions than they pay for read functions.

Therefore, by reducing the number of write transactions, OR by reducing the work required to send write transactions, even if it takes more work to send read transactions later, this will reduce the NFT minting costs that users pay!

And that’s exactly what ERC721A accomplishes.

When it comes to NFT mints: mo’ storage, mo’ problems. Less storage, less problems.

Brilliant, right?

Unit IDOwner

#100

Alice

#101

<not set>

#102

<not set>

#103

Bob

#104

<not set>

The ERC721A contract only has to set the ownership metadata twice: once for the Alice’s batch and once for Bob’s batch.

However, this means that transferring a tokenID that does not have an explicit owner address set, the contract has to run a loop across all of the tokenIDs until it reaches the first NFT with an explicit owner address to find the owner that has the right to transfer it, and then set a new owner, thus modifying ownership state more than once to maintain correct groupings.

Here’s a test to simulate transfer scenarios and log gas costs:

Mint 1Mint 2Mint 3Mint 4Mint 5

t0

71355

92043

92043

92043

92043

t1

91197

111885

111885

117345

t2

93927

114615

114615

t3

96657

111885

t4

99387

They way to read this chart is to go x-axis first, and then y-axis, like:

  • “Mint a batch of 1 NFT, then transfer tokenID 0”, or
  • “Mint a batch of 3 NFTs, then transfer tokenID 1”, or
  • “Mint a batch of 5 NFTs, then transfer tokenID 4”

From these results, we can see that transferring tokenIDs in the middle of a larger mint batch (i.e. t1, t2) costs more than transferring tokenIDs on the ends of the batch (i.e. t0, t4).

Note that this quick experiment only tracks the cost of a single transfer after mint.

A workaround to decrease transfer costs after batch minting NFTs

Here’s an interesting solution to minimize the total cost of transferring your entire batch of NFTs (original source from William Entriken @fulldecent):

  1. Always mint the maximum allowed number of NFTs during the batch mint.
  2. When transferring, start with the ODD numbered tokens first in ASCENDING order.
  3. After that, transfer EVEN numbered tokens.
Making subsequent transfers cheaper to execute
Making subsequent transfers cheaper to execute

This strategy works because it forces population of the \_addressData mapping, making subsequent transfers cheaper to execute.

Examples of NFT projects using ERC721A contracts

Here is a set of projects that are currently using the ERC721A contract:

  • @AzukiZen
  • @cerealclubnft
  • @TheLostGlitches
  • @standardweb3
  • @KittyCryptoGang
  • @XRabbitsClub
  • @WhaleTogether
  • @pixelpiracynft
  • @dastardlyducks
  • @MissMetaNFT
  • @StarcatchersNFT
  • @LivesOfAsuna
  • @richsadcatnft
  • @themonkeypoly
  • @womenofcrypto_
  • @TravelToucans
  • @HuhuNFT

ERC721A alternatives for batch minting NFTs

And for those who are more adventurous, take some time to check out an even newer optimization of the ERC721 standard called ERC721Psi:

Newer optimization of the ERC721 standard called ERC721Psi
Newer optimization of the ERC721 standard called ERC721Psi

We won’t get into ERC721Psi in this article, but if you’re curious and want to learn more about how that one works, let me know by shooting me a tweet @thatguyintech, and I’ll be sure to do another deep dive on it!

We can even explore deploying some sample projects using Alchemy.

Are ERC721A contracts still considered NFTs?

The short answer is yes, ERC721A contracts are definitely NFTs.

Any contract that implements the ERC721 token standard or ERC1155 interfaces are considered non-fungible tokens or semi-fungible tokens.

ERC721A is an extension and optimization of the ERC721 standard.

The same is true for ERC721Enumerable and ERC721Psi.

They’re all part of the ERC721 family!

How to burn ERC721A tokens

When you want to get rid of an NFT or a token that you have in your wallet, but you don’t want to give it to another person, and you don’t want to sell it, you can burn it by sending it to a specific wallet address that no one uses.

A lot of people like to use the same burn addresses because they are easy to remember.

For example, the 0 address:

0x0000000000000000000000000000000000000000

However, when it comes to ERC721A NFTs, you cannot transfer tokens to the 0 address to burn NFTs because most tokens minted in a batch are mapped to the 0 address by default.

Pick another address with which to burn your ERC721A NFTs and you’ll be fine!

For example, another common burn address is the "0xdead" address: 0x000000000000000000000000000000000000dEaD

Will you use the ERC721A contract to batch mint your NFTs?

The ERC721A contract is a powerful way to save your community gas costs and save the Ethereum network from unnecessary congestion by batch minting NFTs.

Let us know what kind of an NFT project you’re building and how we can help! We have tools to help you deploy, monitor, notify, and market your next NFT collection.

Don’t wait, shoot us a tweet @AlchemyPlatform or send a DM and let’s chat!

Alchemy Newsletter

Be the first to know about releases

Sign up for our newsletter

Get the latest product updates and resources from Alchemy

A
O
D
+
Over 80,000 subscribers

By entering your email address, you agree to receive our marketing communications and product updates. You acknowledge that Alchemy processes the information we receive in accordance with our Privacy Notice. You can unsubscribe anytime.