Hey everyone,
I’m working on a project where I need to include image data in my NFTs using Scrypto. I’ve got some JPEG and PNG files that I want to incorporate into the NonFungibleData structure, but I’m not sure about the best way to do this.
I’ve been considering using Decimal or maybe a HashMap, but I’m not entirely sure if these are the right approaches. Has anyone here done something similar before? What would be the most efficient way to store and handle image data within an NFT?
Here’s a basic example of what I’m trying to achieve:
#[derive(NonFungibleData)]
struct MyNFT {
name: String,
image_data: // What type should I use here?
}
fn create_nft(&mut self, name: String, image: // How should I pass the image data?) {
// Logic to create NFT with image data
}
Any tips or code snippets would be super helpful. Thanks in advance!
hey elias87, cool project! have u thought about using IPFS for storing images? it’s decentralized and gives u a unique hash for each file. u could just store the IPFS hash in ur NFT data instead of the whole image. might be more efficient, especially for bigger files. wat do u think?
I’d recommend considering a hybrid approach for your NFT image integration. Store a compressed version of the image data on-chain using a Vec for quick access, while keeping the full-resolution image off-chain with IPFS. This way, you get the benefits of both worlds - fast loading of thumbnails and the ability to access high-quality versions when needed.
For your Scrypto struct, you could do something like:
#[derive(NonFungibleData)]
struct MyNFT {
name: String,
thumbnail: Vec<u8>,
full_image_hash: String
}
This setup allows for efficient on-chain storage while maintaining the option to retrieve the full image when necessary. It’s a balance between performance and cost-effectiveness that might suit your project well.
hey there Elias87! thats a super interesting project youre working on. im curious, have you considered using a Vec to store the raw image data? it might be a good option for handling binary data like jpegs and pngs.
something like this could work:
#[derive(NonFungibleData)]
struct MyNFT {
name: String,
image_data: Vec<u8>
}
fn create_nft(&mut self, name: String, image: Vec<u8>) {
// Logic to create NFT with image data
}
but im wondering, how big are these image files? if theyre pretty large, you might want to think about storing them off-chain and just including a reference or hash in the NFT data. what do you think about that approach?
also, have you looked into any compression techniques? might be worth exploring to save on storage costs. what kind of performance requirements do you have for accessing the image data?