- Victor Arnau
First date with IPFS
In today’s digital age, storing and sharing data has become a crucial aspect of our lives. With the increasing amount of data being generated every day, traditional cloud storage solutions are struggling to keep up with the demand for efficient and secure data storage. This is where InterPlanetary File System (IPFS) comes in, offering a decentralized and distributed storage solution for the modern web.
What is IPFS
IPFS allows users to store and access content without relying on a centralized server. Instead, files are distributed across a network of nodes, making them more resilient to censorship, and improving the overall speed and availability of the content. When a user uploads a file to IPFS, it is divided into smaller pieces called blocks, which are then distributed across the network. Each block is assigned a unique cryptographic hash, which serves as its identifier.
Advantages using IPFS
There are several advantages to using IPFS over traditional centralized hosting services:
- Decentralization: IPFS allows for a decentralized web, where files are stored and served by a network of nodes rather than relying on a single centralized server. This makes it more resilient to censorship and improves content availability.
- Security: IPFS uses encryption to secure the content stored on its network, making it more secure than traditional hosting services. Additionally, IPFS provides immutable content addressing, which ensures the integrity and authenticity of the content.
- Efficiency: IPFS is designed to be more efficient and scalable than traditional hosting services, with the ability to distribute large files across a network of nodes. This improves content delivery and reduces the load on any one particular node.
- Cost-effectiveness: IPFS can be a cost-effective alternative to traditional hosting services, as it is designed to be more efficient and scalable, reducing the need for costly infrastructure.
- Interoperability: IPFS is designed to be interoperable with other web protocols, making it easier to integrate into existing web applications and platforms.
Availability and integrity of files uploaded to IPFS
When you add content to IPFS, it is not automatically stored on every node in the network. Instead, nodes in the network may only store content temporarily and discard it when it’s no longer needed. This is done to ensure that the network operates efficiently and to prevent nodes from being overloaded with unnecessary content.
However, there may be situations where you want to ensure that a particular piece of content is always available on the IPFS network, even if it’s not being accessed frequently. This is where pinning comes in. By pinning content, you’re telling the network to keep a copy of that content available on your local node, ensuring that it remains available even if other nodes in the network discard it.
Vottun has its own IPFS node, which ensures that all your files are pinned to our node when you use our APIs. This means that even if a file is not requested for a long period of time, it will still be accessible when requested.
IPFS & NFTs use case
A NFT is composed with the graphic representation of the asset stored on IPFS, and the token itself stored on the blockchain.
The digital asset, such as an image or a video, which is stored on IPFS. This asset is represented by a unique cryptographic hash that serves as its address on the IPFS network. When someone buys an NFT that represents this asset, they receive a reference to this hash in the NFT’s metadata, along with other information such as the title and description of the asset.
A NFT is the token itself, which is created and managed on a blockchain such as Ethereum. The token is represented by a unique identifier, or token ID, which is associated with the ownership and transfer of the digital asset. The token ID is typically stored in a smart contract on the blockchain, along with the metadata that describes the asset.
When someone buys an NFT, they are essentially buying ownership of the token, which gives them the right to transfer or sell the token to someone else. The token serves as a digital certificate of ownership for the underlying digital asset stored on IPFS. Because the token is managed on a blockchain, ownership of the NFT can be tracked and verified in a transparent and secure way.
The two parts of an NFT work together to create a unique and valuable digital asset that can be bought, sold, and traded in a decentralized and transparent way. The digital asset is stored on IPFS, while the ownership and transfer of the asset is tracked and verified on the blockchain through the NFT token. This allows creators and collectors to monetize and exchange digital assets in a new and innovative way.
Storing NFT Metadata and Tracking Ownership on the Blockchain with ERC721 Standard.
When an NFT is created, the smart contract stores its metadata, which includes information such as the name and description of the asset, as well as the IPFS hash that points to the graphic representation of the asset stored on IPFS. The metadata is stored on-chain or off-chain, depending on the implementation, and is typically accessible through a public function in the smart contract.
The ERC721 standard defines a set of events that can be emitted by the smart contract when NFTs are created, transferred, or destroyed. These events can be used to track the ownership and movement of NFTs on the blockchain.
Here’s an example of the metadata schema for an ERC721 NFT:
Introducing to IPFS with Vottun
But how do you upload files to IPFS? This is where the Vottun API comes in. The Vottun API provides a simple and easy-to-use interface for uploading files to IPFS. By using the Vottun API, you can take advantage of the benefits of IPFS without having to worry about technical details.
From the Vottun API we have 3 ways to interact with ipfs.
1 – Upload a single file:
Endpoint: https://ipfsapi-v2.vottun.tech/ipfs/v2/file/upload
Its content type must be multipart/form-data and will include two fields:
filename: A name for the file
file: the file itself
The complete call launched from curl:
And from NodeJS:
Response:
2 – Upload a zip with multiple files
Endpoint: https://ipfsapi-v2.vottun.tech/ipfs/v2/upload/zip
Its content type must be multipart/form-data and will include one field:
file: the file itself
The complete call launched from curl:
And from NodeJS:
Response:
3 – Upload metadata
Endpoint: https://ipfsapi-v2.vottun.tech/ipfs/v2/file/metadata
Its content type must be application/json and will include the data:
And from NodeJS:
Response:
Conclusions
In this article we learn:
- IPFS is a decentralized protocol for storing and sharing files that provides several advantages over traditional centralized hosting services. Its use of distributed networks makes it more resilient to censorship and improves content availability, while its immutable content addressing ensures the integrity and authenticity of the content.
- What is IPFS
- Why use ipfs instead of another service
- Availability and integrity of files uploaded to ipfs
- Endpoints avalaibles to interact with ipfs from Vottun API
In future articles we are going to go deeper into Vottun APIs and different standards such as rental NFTs (ERC4907).