Sound Protocol
Overview
ERC721a Info

ERC721a Info

The following is some info and recommendations to help developers get the most from the ERC721a standard (opens in a new tab) that SoundEdition implements.

ERC721A vs ERC1155

ERC721AERC1155
O(1) ownerOfYesNo ownerOf
O(1) balanceOfFor all tokensWithin fungible tokens
O(1)* bulk mintFor all tokensWithin fungible tokens
# mint SSTOREs31

* Approximately O(1) for ERC721A.

For unique collections, ERC1155 needs a counter which needs 1 more SSTORE.

ERC1155 requires centralized indexing services to emulate ERC721-like functionality off-chain.

Transfers

For users, it is more gas optimal to transfer bulk minted tokens in ascending token ID order.

For example, if you have bulk minted token IDs (33, 34, ..., 99),
you should transfer in the order (33, 34, ..., 99).

This is due to how the lazy-initialization mechanism works internally:
it scans uninitialized slots in descending order until it finds an initialized slot.

Aux

Consider using ERC721A._getAux and ERC721A._setAux to get / set per-address variables
(e.g. number of whitelist mints per address).

This can help remove an extra cold SLOAD and SSTORE operation.

Minting

For typical artwork collections, consider using _mint over _safeMint if you don't expect users to mint to contracts.

Batch Size

During transfers, ERC721A scans through ownership storage slots until it finds an initialized slot.

To prevent expensive first-time transfer fees for tokens minted in large batches, either:

  • Restrict the max batch size for public mints to a reasonable number.

  • Break up excessively large batches into mini batches internally when minting.

  • Use ERC721a._initializeOwnershipAt every couple tokens to reduce number of reads during a transfer.

Efficient Tokenomics

ERC721A keeps track of additional variables in the internal mappings.

  • ERC721a.startTimestamp (starting time of holding) per token.
  • ERC721a.numberMinted per address.
  • ERC721a.numberBurned per address.

These variables hitchhike on the SLOADs and SSTOREs at near zero additional gas cost (< 1%).

You can use them to design tokenomics with very minimal gas overhead.

The ERC721a.startTimestamp, is available via the ERC721a.TokenOwnership struct.

You can get it from the ERC721a._ownershipOf function or the non-reverting ERC721a.ERC721AQueryable.explicitOwnershipOf function.

Other Implementations

ERC721A is not a one-size-fits-all solution.

It is heavily optimized for generative artwork NFT collections.

If your collection does not expect a busy mint phase (e.g. a pure utility NFT),
or does not require bulk minting,
these excellent implementations can be better for lowering overall transaction fees:

Use the right tool for the job.