What is IPFS? How can it store NFT data and what does it do?
IPFS is an open source hypermedia protocol that allows peer to peer (p2p), decentralized data storage via:
- Sharing simplified
- Resistance to censorship
- Simple retrieval
IPFS uses its advanced file versioning features to help you find the right content. IPFS also decides to move data across the network.
These three steps are the foundation of an IPFS ecosystem:
Step 1: Content Identification through unique identification
After users upload NFT data to IPFS, they are given an IPFS hash and a CID. CIDs are unique identifiers of NFT data that can be used to refer to the content, regardless of where or how it is stored.
Step 2: Content storage and linking through DAGs
IPFS allows for decentralized data storage and retrieval to ensure the long-term preservation of NFT data. IPFS' permanence layer uses cryptographic proofs that ensures the NFT data is persistent and durable over time. IPFS uses a Merkle DAG that is optimized to represent directories and files when it comes NFT data linking. A Merkle DAG can be structured in many ways.
Step 3: Content retrieval through Distributed hash table (DHT).
IPFS uses a distributed hash table to determine which peers have the NFT data. A hash table is a database that contains keys and values. This hash table is shared among all peers of a distributed network in which the libp2p handles interactivity and connectivity between peers. To find out which peers have each block of NFT data, the libp2p queries DHT. Once you have found the content, connect to it (NFT data) to retrieve it.
What are the best ways to store NFT data in IPFS?
1. Different types of IPFS links for different use-cases
There are many ways to refer to IPFS data, each suitable for different uses. Below are some of the options.
- CID (Content Identification Identifier)
CIDs are a self-descriptive unique identifier that identifies any content regardless of its location. They are stored in binary format and can be transferred across the network. They are displayed to users as strings of randomly-seeming characters.
- URI (Uniform Resource Identifier)
To identify particular content within a context, the IPFS URI Uniform Resource Identifier (or IPFS URI Uniform Resource Identifier) is used. The URI scheme identifies context (appended as a prefix to the URI, followed by ://).). The URI scheme for IPFS is simply IPFS.
- HTTP Gateway URL
The HTTP gateways allow legacy browsers to communicate with each other even if they are unable to resolve IPFS URLs natively. These links can be used in the application's presentation layer, without being stored on a blockchain or within NFT metadata.
How can you address content in different situations?
The NFT smart contract will return an IPFS URL to the assets and metadata that are confined to each token.
Before casting any token or locating it on-chain, create the IPFS URI. This indicates that smart contract interfaces require URI. The ipfs:// URI scheme makes a app see that data is still available with IPFS.
It is recommended to link IPFS content via the IPFS URL and the HTTP gateway URL. This is for user-facing applications. You can generate gateway links using an IPFS or CID depending on the requirement.
An example of an HTTP gateway URL that targets the public gateway at www.dweb.link would be:
The NFT value is incomplete without metadata. Structured metadata is required for most NFTs to describe the properties of tokens. It is therefore important to store metadata in a JSON object encoded to UTF-8 byte strings. An IPFS URI is better than an HTTP gateway URL to link to images, videos, and other media. Gateway URLs can be created in your application's presentation layer.
Here are the steps to access the metadata linked:
Step 1: Create directories that are separate for metadata and assets.
Step 2: Add assets and directories to be created.
Step 3: Add the asset catalogue to IPFS and note its ID.
Step 4: Create metadata in your directory using CID reference assets to create IPFS URIs.
Step 5: Add metadata directory to IPFS, and note its CID.
Step 6: Create an IPFS URL with the CID you have noted and store it in order to create an ownership record.
3. Data persistence and availability
NFT data can be retrieved from any IPFS node that has its copy. This allows for easy data transfer and reduces server load. The user saves a copy of the data when fetching it to be able to help other users later. These temporary copies can be deleted when the user wishes to pin the data.