How are NFTs stored? On-Chain, Off-Chain and Decentralized Storage
by James · August 25, 2022
Non-fungible tokens (NFTs) is ultimately a form of digital media. And just like other digital media – from the words typed Decrypt articles to YouTube videos and streamed music – NFTs, in their most basic form, consist of data made up of 1s and 0s.
It is important because everything related to NFT from smart contract it feeds into the URL you use to display it to the image itself—ultimately boils down to 1s and 0s stored on a computer.
Not all NFT storage techniques are created equal. Some NFT holders may not own much more than a URL or token ID. So it’s worth taking the time to understand how NFT storage works before thinking about buying or creating an NFT.
Before we dive in, let’s take a look at some core concepts:
- 🖥️ Servers—A server is a computer, just like the one you are reading this article on. However, unlike the computer you are reading this on, servers are exceptionally powerful and can run many different programs simultaneously. At the root, NFTs live and are stored on servers.
- 🖧 Hosting— The vast majority of people do not run their own servers, so whether they realize it or not, they are dependent on someone else offering that service. Hosting refers to a collection of services, including storage, that typically run on servers. All NFTs are hosted somewhere.
- 💽 Metadata—Metadata is data that describes other data. Metadata helps servers find, process and store data more efficiently. The metadata of an NFT describes properties such as (for a PFP NFT) its name, color, size, shape, hat type, glasses type, etc.
- #️⃣ Hash— A hash is a cryptographic function that, given some input, produces the same output every time. A hash is usually used to encode and lots of information verifiably and effectively. An NFT and all its metadata can be stored in a single hash. To get hands-on experience with hashing, check out this hash generator.
- 📝 Smart contract—Smart contracts are coded instructions that live on a blockchain. They are the building blocks of decentralized applications (dapps), including most NFTs. The rules for minting and exchanging NFTs live in smart contracts.
On-chain vs off-chain storage
Storing an NFT on-chain means that the entire NFT—the image and all its metadata—exists on one blockchain. Conversely, off-chain stored NFTs mean that some or most of the NFT is stored outside the blockchain.
On-chain storage may be preferable because it means users can verify all facets of the NFT. However, very few NFT projects choose this storage method.
An example of one that does is Autoglyphs. The reason for this is simple – JPEG images contain a lot of data, especially when these images exist in collections in the order of thousands or tens of thousands.
As a result, most NFT projects choose to store the actual images off-chain. Many famous NFT projects like CryptoPunks and Bored Ape Yacht Club opt for off-chain storage.
Centralized vs decentralized hosting
When it comes to off-chain storage, NFT’s smart contract contains information that points to an off-chain location where the NFT JPEG image itself is stored. Often the NFT image and its metadata are stored in a hash.
This hash is used to point to either a centralized or decentralized hosting provider.
Examples of centralized hosting providers include Amazon and Google. Centralized hosting providers run servers that store the 1s and 0s that make up the NFT.
The risk for centralized hosting providers is that (although unlikely) they could shut down at any time and the owner’s NFT would be lost. All the owner will be left with is, in some cases, like a simple hash found in a smart contract.
That is why many projects choose to use decentralized solutions to host their NFTs. The most common solution is to host NFT data on the InterPlanetary File System (IPFS). IPFS is a distributed peer-to-peer network where files are stored across multiple nodes, making them resilient to single points of failure, such as server problems.
While NFTs stored on IPFS are not technically stored on-chain, they are theoretically more secure because IPFS is censorship-resistant; no single entity has the power to shut it down.