An implementation of On-chain image storage to the current metaplex nft standard
This standard utilizes the existing fields of the metaplex nft program to be able to store an on-chain image
Creating this topic to discuss how I stored images on-chain on solana with the NFT project known as Blockrons as a proof of concept.
Blockrons was built in december 2022, before there were much interest on on-chain solana nfts. The goal of the project is 2 fold, implement a true on-chain nft as well as educate the degen/twitter audience on why/how on-chain nfts are done on solana.
The image data is stored as a string directly to a solana address. The format is base 64 SVG, which is a great format to store pixel art. The idea was not to complicate things with advanced struct or json’s but rather simply store the data in an address in such a way that a simple data retrieval call on the solana address will return the image data without needing additional decoding or struct deserialization.
The string also uses a data URL header, this allows browsers to native read the string data into an image. Therefore all strings start with: “data:image/svg+xml;base64,(data here)”
Connection to the NFT token:
To connect this PDA image storage account to an existing metaplex NFT, we use 3 methods.
Method 1 is write the image storage account on the NFT description, however since the description itself is in a json stored off-chain, this is not a good implementation.
Method 2 is the fact that the image storage account is a PDA generated with the NFT token pubkey as a seed (the other half of the seed is the programID). This makes it easy to retrieve the image storage account knowing just the programID and the nft token pubkey.
Method 3 is writing the image storage account directly to the URI field. This is done by appending the solana account pubkey after the arweave (off-chain) link. Wallets and marketplace still resolve to the arweave link, we can keep the image storage account written there for manual image retrieval.
You can see the highlighted green area above to show how the image storage account was added to the URI field.
If you would like to test how images are stored, visit this link: https://onchain-datagrabber-developerhamster.vercel.app/
This website was built to showcase to the audience how the images are stored and retrieved in a step by step process. If I were to automatically retrieve the image on-chain, then how can you illustrate/educate to the audience that the images are on-chain?
This proposal aims to introduce the “/?onchain=” append to the metaplex URI field as a standard way to store on-chain image accounts.