ERC721A - Mint multiple NFTs at the cost of minting one
NFTs are primarily using the ERC-721 standard which is considered the gold standard. While the Gaming industry uses ERC1155 to deal with both Fungible and Non-Fungible tokens in a single contract.
Minting NFTs will cost us the gas fee since it updates the storage to add new tokens and does computation while doing that. This gas fee is getting higher and higher because of more and more people getting into the blockchain world.
ERC721A – Solid Gas Saving Contract
This standard is built by the Azuki team (https://www.erc721a.org/), which is an improved implementation of ERC721. It is a tradeoff between storage and computation. The main difference appears to be in the storage of token IDs against the address in ERC721. Whereas the ERC721A uses computation to derive the ownership of the token.
During batch minting, the ERC721 need to call the mint function multiple times and thereby adding the token to the owner in the memory storage each time.
function _mint(address to, uint256 tokenId) internal virtual {
require(to != address(0), "ERC721: mint to the zero address");
require(!_exists(tokenId), "ERC721: token already minted");
_beforeTokenTransfer(address(0), to, tokenId);
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(address(0), to, tokenId);
_afterTokenTransfer(address(0), to, tokenId);
}
While doing batch minting, each mint call updates the balance by 1, which again adds up to the cost of the gas fee. Since we know the total mint quantity, it can be improved by just increasing the balance from existing to balance + quantity. Doing this will make the update call only once thereby reducing the gas fee by 90%.
The other optimization is the owner info data storage. ERC721 uses tokenID -> address mapping which updates the owner info for each token id. If the owner mints 5 tokens at a time, it is better to store the owner info to the first token and store the quantity. Thereby while calling the owner we can reverse track the owner from the no of tokens the owner minted.
Hence the above optimization reduces the gas fee by almost 90%. Below is the chart from the
NFT community already adopted this ERC721A as stated here
ERC721A implementation : Github