I was curious about leveraging ERC721A’s extraData as a “storage hitchhiking” feature for token-related data. However, I couldn’t find any existing implementation of _setExtraData, so I decided to build one myself.
This repository demonstrates:
- Setting
3 bytes (uint24)
of extra data in an external mint function - Retrieving the extra data with a public getter function
- Preserving the extra data on transfers between non-zero addresses by overriding _extraData
For more details, check out the official ERC721A documentation to understand the underlying mechanism.
$ forge test
It's just an example contract, do NOT blindly copy anything here into production code unless you really know what you are doing.