An Introduction to On-Chain DNA: A Sustainable way to Store and Manage Data within the Blockchain
The world of NFTs (Non-Fungible Tokens) is constantly evolving, with great developers and creators innovating on new utilities, mechanics, and NFT interactions all the time. Today we present an open-source and comprehensive approach to managing NFT data on the blockchain, which is flexible, scalable, and gas efficient.
What is On-Chain DNA?
On-Chain DNA stores NFT data as a single bytes data field called “dna” in the NFT token contract combined with an off-chain data format or schema. This allows developers the ultimate flexibility to store a wide range of information about each NFT, including traits, attributes, and metadata. Unlike other NFT projects, On-Chain DNA only adds the dna field to the NFT token contract. It takes the guesswork out of guessing the intent of esoteric contract methods and makes it easier to integrate with other systems and platforms.
Instead, with Owl Protocol’s implementation, using an off-chain data schema can be as verbose as required without concerns about data size or bloating the NFT smart contract. Developers may be familiar with this concept, similar to other data compression schemes such as MsgPack or ProtoBuf.
Also, by moving complexity to a standard JSON Schema, it can be parsed by any application in a more powerful engine and used programmatically, so even if there is some guesswork involved, the extra verbosity of the schema should allow for easier integration with any interface.
Our approach is to expose the dynamic features through the standard tokenURI method.
Which no longer just concatenates the baseURI and tokenId, but now returns the ABI encoded dna. Further examination will reveal that the getDna function does a recursive call to get all child NFT dna data as well. With this ERC721TopDownDna implementation, we have a very powerful tool to store complex data with multiple NFTs in a hierarchical format and still expose all of it to the root/parent NFT.
What is ultimately returned is an endpoint (can be later decentralized with IPFS, or another decentralized compute network) that anyone can run because it’s open-source, which returns the NFT standard metadata, but is dynamically generated based on the dna.
Deciphering the NFT Data (DNA)
While the dna field provides a flexible way to store NFT data, it is not very useful by itself. Like MsgPack or protoBuf, the dna data requires a schema to decode and interpret. This schema is stored on IPFS in JSON format, and only the IPFS hash is added to the NFT smart contract as part of the baseURI.
For example, a typical tokenURI(tokenId) method call to the smart contract itself will return something like this:
Which follows the format:
To access the NFT metadata, a decentralized application can parse the IPFS hash and the dna and pass them to the client-side SDK. The client-side SDK will generate the NFT’s metadata, typically including the NFT rendering/image as a link or base64 encoded image.
The Collection Schema JSON
The Collection Schema JSON defines how the traits of an NFT are encoded into bytes. For example, a typical Schema JSON may look like this:
In conclusion, the On-chain DNA feature allows NFTs to have dynamic and customizable traits, making NFTs more versatile and valuable in gaming and beyond.
With the standardization of the tokenURI method and the use of IPFS to host the Collection Schema JSON, it is easier for developers to integrate and use NFTs in their projects, without having to deal with the technical challenges of customizing integrations for each NFT collection.
If you’re interested in learning more about Owl Protocol and how it can help you in your projects, please feel free to contact us at our discord https://discord.com/invite/7sANzfGUfe.
To read more about our dev documentation — access https://docs.owlprotocol.xyz