Search code examples
nftscrypto

How to get image data into nft data


Assume I have a .jpg or .png file, I want to integrate this image data into a NonFungibleData in Scrypto, how can I do it? Should I use Decimal? HashMap?


Solution

  • Normally, you wouldn't store the image inside the NFT metadata (it would cost too much).

    What you could instead do is host the image using IPFS and store its link along with the hash of the image in the metadata of the NFT.

    Here is an example:

    #[derive(NonFungibleData)]
    struct BoredGumballClub {
        ipfs_link: String,
        image_hash: Hash,
        hat: Hat,
        eyes: Eyes,
        mouth: Mouth,
        shirt: Shirt
    }
    

    At the moment, there are no standards around the name of the fields you should have on the NFT metadata to be able to display them correctly on explorers and wallets. Standards should emerge the closer we get to Babylon.