During the @0xTajigen mint, we regularly saw transaction fees under $1 (58,452 gas to mint 3 tokens). Let's dive into the why and how of TinyERC721, a new ERC721 implementation that reduces gas usage for mints and transfers by ~30% compared to other contracts like ERC721A. 1/15
While it is nice to see these sub-1 dollar transaction fees, this is mainly affected by cheap gas fees. Reducing gas consumption has a much larger impact when gas prices are high. 2/15
During the previous bull market, we would often have days with gas prices around 100-150 gwei. This resulted in over 10,000 ETH a day spent on transaction fees. Reducing NFT-related gas consumption by 30% could save the ecosystem millions of dollars a day. 3/15
The ERC721 standard specifies an interface for non-fungible tokens, which makes it possible to build NFT-aware tooling. The standard aims to be flexible enough to support a variety of different use cases. 4/15
While the design space for NFTs is massive, the majority of projects today put a big emphasis on scarcity and often have a number of additional characteristics. 5/15
Following the success of CryptoPunks, most collections use a similar model of issuing a limited number of tokens, often 10,000 or less. These tokens are typically minted during an initial sale phase and assigned sequential ids, until the maximum collection size is reached. 6/15
The ERC721 reference implementation and the popular OpenZeppelin ERC721 contract provide a flexible base that can support all kinds of collections. TinyERC721 looks at the needs of most NFT collections today and gives up some of this flexibility to reduce gas consumption. 7/15
The main way to reduce gas usage is to reduce the amount of data you need to store on-chain. Storing data costs 20,000 gas per storage slot of 32 bytes. Even if you just need to store a single bit, you need to pay for the whole storage slot. 8/15
It is possible to store multiple pieces of data in a single storage slot. For example, if you need to store an address (such as the owner of a token), which takes up 20 bytes, you still have 12 bytes that you can use for no additional cost. 9/15
In a typical ERC721 contract, 2 pieces of information are stored. The first one is token ownership. While the OpenZeppelin ERC721 contract stores the owner for each individual token, ERC721A uses a technique to store the owner just once when a batch of tokens is minted. 10/15
The second piece of information is the token balance of an address. The Nuclear Nerds contract by Mason and Chance does not store this value, but dynamically calculates this by looping through the entire collection and counting the number of tokens owned by that address. 11/15
TinyERC721 combines the batch mint optimization by ERC721A with the dynamic balance calculation by Mason and Chance. The result is a contract that not only optimizes gas usage for batch mints, but also reduces gas usage for each subsequent transfer. 12/15
One disclaimer I want to add is that I am NOT saying that this contract is better than any of the other ERC721 implementations that exist. TinyERC721 makes different tradeoffs to reduce gas consumption, which may or may not be worth it given your specific situation. 13/15
As with so many things in software engineering, it's all about tradeoffs. TinyERC721 aims to give developers one extra choice if their use case meets certain criteria. 1. sequential token ids 2. does not need on-chain balance queries 3. capped collection size 14/15
Thank you for reading the whole thread. If you want to use this in your own project, check out the GitHub repository: https://github.com/tajigen/tin... If you have ideas on how to improve this, reach out to me here or in the @0xTajigen discord 15/15
Here's a link back to the first tweet. If you think it would be valuable to see more widespread adoption of gas-efficient NFT contracts, please retweet to spread the word. https://x.com/wakemi18/status/...
@wakemi18 @0xTajigen Great work! I really like your breakdown. I'd be curious to your thoughts on the other side of the tradeoffs of the different contracts. If the mint is cheaper, what are we trading off? e.g. do transfers cost more gas; do certain use cases not work like games
@knowrat @0xTajigen With the batch mint optimization, which is what ERC721A does, you repay the initial gas savings during future transactions which will fill in the empty ownership data. The thesis is that gas wars could cause gas to spike during mint, but you can transfer tokens when gas is cheap.
@wakemi18 @0xTajigen thank you!
@wakemi18 @0xTajigen Awesome thread. As much as Ethereum fees may decrease with The Merge in the short term, there is no doubt they will rise again as the blockchain becomes more mainstream. Therefore, optimizing gas use, like TinyERC721 does, will still be as important as ever.



