Interplanetary File system IPFS powers the Blockchain (Part 18)

Techskill Brew
Blockchain 101 by Techskill Brew
6 min readMar 16, 2022

Welcome to the 18th part of the 100 part series on Blockchain.

Previous parts: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 and 17.

In the traditional web application, the data is stored on centralized servers owned and operated by an organization, giving it full authority over the app and the data. Also, centralized data storage may have availability issues. Let’s say you want to download an image abc.png from the domain xyz.com. For this, you tell the computer exactly where to find the image. The location of the image is the URL address, i.e., xyz.com/abc.png. This is called “location-based addressing.” But suppose if the server is down, or the file has now been removed from the servers for whatever reason, you won’t be able to access the image anymore. However, there is a probability that someone else has downloaded the image before and has a copy of it. But yet, there is no way of connecting to them and grabbing a copy of the picture from that person.

To solve this issue Interplanetary File system, abbreviated as IPFS storage solution protocol, is used, which uses “content-based addressing” instead of “location-based addressing.”

Centralized and decentralized data storage

IPFS and Content-based addressing

IPFS is a peer-to-peer decentralized protocol for storing Blockchain-based data. In this, instead of saying where to find a resource, you just say what it contains. Also, rather than referring to objects as pics, articles, or videos, IPFS refers to everything by the hash on the file. Every file has a unique hash, which can be compared to a fingerprint. Therefore, when you want to download a certain file, you will ask the network, “who has the file with this hash?” and someone on the IPFS network will provide it to you. The hash function allows you to check the integrity of the obtained file by comparing the requested hash with the hash of the received file. If the hashes match, it means you received the file as it is; it has not been modified.

The hash function also helps de-duplication, such that no file with the same content can be submitted twice since the same content generates the same hash. This optimizes the storage requirements and also improves the performance of the network.

How can Blockchain data be stored on IPFS?

Blockchain is an expensive medium for data storage. It costs around $100 per GB of storage. For efficient storage of extensive data and content, Inter-Planetary File System, abbreviated as IPFS, can be used which is a distributed, decentralized file system and a platform to store data and files with high integrity and resiliency.

Let’s now understand how data is stored in the IPFS system:

(i) Files are stored as IPFS objects. 256 kB of data can be stored inside one IPFS object. Therefore the file up to size 256 kB can be stored in a single IPFS object. But what about the files that are larger than 256 kB, like an image or a video file? Such files are split up into multiple IPFS objects that are all 256 kB in size and are stored across a network of nodes. Nodes of the IPFS are incentivized for providing storage space on their computer or server for hosting/storing files. Anyone can install and run an IPFS node on their computer.

Each IPFS object is identified with its own hash. For example, suppose you want to store a file of size 1MB, whose hash is, say, 85bcd. The file will be split into 4 chunks of 256 kB each, and each chunk will have its unique hash (content identifiers or CID), say 09afg, 6efab, 45af, and 23hbc. When the chunks are assembled together, based on their hash value, it recreates the original file.

(ii) IPFS system also creates an empty IPFS object that contains an array of links to IPFS objects of the file. These links of IPFS hashes are stored into the Blockchain smart contracts to provide traceability and authenticity. And the content of the files is stored on IPFS.

If there is any change in the content of the digital document, the hash changes, which indicates that the original content was modified and altered.

How can Blockchain data be stored on IPFS?

How to share files on the Blockchain with IPFS?

Suppose you have uploaded a PDF file on the IPFS network. The hash of the file is stored on the Blockchain. Anyone knowing the hash of the file can retrieve the file from IPFS and read its data.

Asymmetric Encryption: Since as long as anyone has the hash of the PDF file, they can retrieve it from IPFS. So sensitive files can not be stored as such on the IPFS network. This problem can be solved by using cryptographic public and private keys. You need to encrypt the file with the intended recipient’s public key so that only they can decrypt it. A malicious party who retrieves the file from IPFS can’t do anything unless it is decrypted — coming to our example. Suppose you uploaded a PDF file on the IPFS network that only Mat can access. After knowing the hash of the file, Mat can retrieve the encrypted file from the IPFS network. He can now decrypt the file using his private key and know its contents.

Asymmetric encryption to securely share files on the Blockchain with IPFS

Few use cases of IPFS in storing Blockchain data

(i) Non-Fungible Tokens or NFTs: A NFT is a type of digital certificate that guarantees ownership of a unique digital asset such as a song, an image, art, videos, game, etc. NFTs can’t be directly stored on the Blockchain as storing that much data on the Blockchain is expensive and consumes a lot of electricity. Here is where IPFS comes in. The specifics of the NFT, including the sale agreement between the NFT owner and buyer, information regarding the creator of the work, royalties, etc., can be stored directly on the smart contracts. But NFT data or digital assets can be stored in IPFS. And the link to the data on IPFS is also included in smart contracts, which can be accessed by the owner only.

(ii) Storing Electronic Health Records (EHR): IPFS also allows for safer storage of patients’ health data, and Blockchain limits the data access to only authorized users, e.g., healthcare providers, insurance companies, etc.

(iii) IPFS can be an excellent tool for dApps as it can be used to store any dApp data. For example, in the case of educational dApp, course content, assignments, blogs, articles, etc., can be stored on decentralized IPFS. And in the case of streaming dApps, video and music content can be stored on IPFS.

If you liked this article and want to know more about Blockchain, NFTs, Metaverse, and their applications, click the below link.

Happy learning!

--

--