'How to store each NFT image in a ERC721 contract? [closed]
When creating a ERC721 contract that manages thousands of image NFTs, saving these image byte pixels in arrays on the contract doesn't seem very scalable.
What is the standard way of doing this?
For eg. CryptoKitties, are they storing each image bytes on the contract itself, or they are a URI pointing to an external resource?
On the other hand, having an URI seems to beat the point of NFTs, because if the URI gets broken (eg. the server with the image goes offline), then as a owner of that NFT, you now only own a URI reference to what would be an image, and not the image itself.
Solution 1:[1]
There are a handful of variables here. But, you can store images onchain as base64 encoded strings. Depending on the complexity of the images, you might want to use multiple contracts.
hot-chain-svg - A toolkit for building on-chain SVG projects.
BOOTCAMP2021 - Example of how to store SVG data in multiple contracts.
Solution 2:[2]
You can probably use third party services such as: https://www.pinata.cloud/
I am in no way affiliated with them, but if you decide to use them, please let us know how it works out. You're basically looking for an IPFS.
Solution 3:[3]
Owning an url is indeed useless because the owner of the website may change the content behind the url or even take it down. You could however store the hash of the image. For example if you have store a SHA-256 of the image, that can never change.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | pheobe |
Solution 2 | parttimeadjunct |
Solution 3 | Albert Hendriks |