How to Make NFTs With On-Chain Metadata
NFTs are blockchain digital tokens that signify ownership of a unique object, including artwork, collectibles, game assets, and membership. While most NFTs store metadata and media files on an off-chain source, an on-chain NFT stores essential metadata within the blockchain.
Storing metadata on a blockchain can enhance an NFT’s independence and durability since its critical metadata will not entirely rely on a separate external server or storage service. But storing bulky files within a blockchain can cost much. This makes it crucial for NFT developers to decide on proper file format and storage method.
Below is a guide to creating NFTs with on-chain metadata.
3 Steps to Create NFTs With On-Chain Metadata
Step 1: Define the NFT Data and Choose a Blockchain
First, decide what kind of information should be included in the NFT. This may be the NFT’s name, description, attributes, image, collection info, and any other information.
For on-chain NFTs, the metadata is stored directly in the blockchain along with the visual file itself when possible, rather than hosted on an outside server.
Afterwards, choose a blockchain that is suitable for your project. Think about transaction costs, block size constraints, and smart contracts capabilities, as well as the overall ecosystem of the platform.
Step 2: Create the Smart Contract and Store the Metadata
Smart contracts are used for the minting process and for fetching the metadata associated with the NFT. In case you choose the EVM-based platforms for NFT development, Solidity is widely used, and there is a choice between ERC-721 and ERC-1155 NFT standards.
In case we talk about the on-chain metadata, then the tokenURI function can include the metadata of the NFT. It will not point out the website URL, but the encoded metadata inside the contract.
Thus, it is possible to store metadata in JSON form as well as to include the fields such as the NFT name, description, and attributes.
It is also possible to create or encode the image within the contract itself.
Step 3: Test, Mint, and Verify
Testing the smart contract on the test network prior to minting NFTs on the mainnet is important to ensure proper functioning of the contract. One needs to see if the metadata is returned properly, if the attributes are displayed, if the NFT is transferred from one owner to another, etc.
Also, gas fees need to be considered as they can increase considerably if the data will be stored on-chain.
After the testing process is finished, deploy the smart contract and mint the NFTs. After minting the NFTs, check if its metadata can be received without connecting to any server outside of the blockchain.
How On-Chain NFT Metadata Works
Metadata about NFTs usually relates to the asset associated with the NFT. Metadata about NFTs usually includes data like its name, description, picture, attributes, and other collections.
For ordinary NFTs, it happens that the NFT itself exists on the blockchain, but the metadata or its picture might not be present there; instead, the URI for this file is specified by the smart contract.
For on-chain NFTs, the metadata is stored on the blockchain itself. Moreover, sometimes the actual picture or artwork of the NFT is also created on-chain.
It is typical to use data URI encoding for the metadata. Smart contracts have the ability to create this metadata dynamically and return it using the metadata method of the NFT.
This way, an NFT is created which does not depend on any centralized website or external databases.
Benefits of On-Chain Metadata
1. Greater Permanence
Because the metadata is recorded on the blockchain, it is less dependent on a centralized hosting provider. This can improve the long-term availability of the NFT’s defining information.
2. Reduced External Dependencies
On-chain NFTs can reduce reliance on websites, private servers, or third-party metadata hosting services. This can make the asset more self-contained.
3. Verifiable Data
Blockchain records allow users to verify the NFT’s metadata and associated information directly through the network.
4. Enhanced Collectibility
For digital art and generative projects, storing artwork or its generation logic on-chain can become part of the NFT’s value proposition. The asset can be closely tied to the blockchain itself rather than simply referencing an external file.
5. Long-Term Accessibility
If an NFT’s essential metadata does not depend on an external service, there is less risk of that particular dependency disappearing or changing unexpectedly.
How to Make an On-Chain NFT
First, create your NFT artwork and metadata. Specify which parts of the data will go on-chain, and which will stay off-chain.
Then, create a smart contract for your NFT based on some token standard. This contract should have proper minting logic implemented, as well as a function that returns token metadata.
Next, you can encode the metadata and include it into the smart contract. Metadata may consist of a JSON object with information about NFT, including its name, description, image data, and other attributes. In this case, the image can be an SVG file or any other data that can be encoded into the blockchain.
Once the contract is deployed on the testnet, create a test NFT and analyze its metadata. Make sure to analyze the token on the blockchain explorer and with NFT-compatible interfaces to verify that the metadata is displayed correctly.
Now, you can deploy the tested contract to the mainnet and mint the actual collection.
Challenges to Consider
The greatest problem for on-chain NFTs is the problem of cost. Storage on the blockchain is finite and costly, especially when large images or complex information need to be stored.
Thus, gas economy takes precedence over all else. One can employ techniques such as small data structures, SVG artwork, procedural generation, or any number of others to minimize the size of the metadata.
Another issue to consider is the issue of smart contracts and their security. A flaw in the contract might influence the generation, accessing, or immutability of the metadata.
It is crucial to remember that the placement of metadata on-chain does not necessarily mean everything becomes immutable and irrevocable. It all depends on the design of the contract itself.
FAQs
What is on-chain NFT metadata?
On-chain NFT metadata is metadata stored in the blockchain instead of the off-chain method which uses an external server to store the information. This may include name, description, attributes, and even in some cases the art of the NFT.
Do on-chain NFTs cost more to create?
They could because the cost of storing data on the blockchain is higher compared to storing the data off-chain, especially for larger files.
Can you store an entire image of the NFT on-chain?
Yes, depending on the size of the file and the type of blockchain used. Some of the artwork that can be stored on-chain includes SVGs and generative artwork since they do not use as much storage as the raster artwork.
Are on-chain NFTs permanent?
Data stored on the blockchain can offer good permanency because it is stored in the blockchain. However, the permanency of this data will depend on the blockchain being used and how the data is stored in the blockchain.
