Photo by David Shares on Unsplash

Blockchain and the supply chain — IPFS

Kushagra Jindal
May 13, 2020 · 3 min read

IPFS stands for Interplanetary File System. It is a protocol used for storing and sharing data in the distributed file system. This file structure is a Merkle DAG, a combination of Merkle trees and Directed Acyclic Graphs. Making IPFS unique in identifying the files, as each file is referred by a hash.

IPFS helps in increasing the security and speed of the network. For example, DDoS attack won’t work as there is no central system and every request can be responded from the nearest node.

In this blog, I will share how we can store metadata for any product in the distributed file system, IPFS.


To start with IPFS, you need to install it in your system. Download the appropriate setup, according to your Operating System from here, and execute the file.

After the installation is done, we can check it by the ipfs command in the console.

ipfs --version

Command ipfs refs local can be used to check all the files that are already on the ipfs server.

ipfs refs local

To get details of any file we can use the command.

ipfs object get QmSEind1iCuGcSFWpt2q1B3FjyTfWZFYY3nrV9KMqDe1BT

An Apple Use Case:-

Now, we will see IPFS in action for an apple recorded in the blockchain. In our use case, we will store two important information about an apple which are the colour of apple (maybe a red apple or a green apple) and the date when the apple was plugged. The date here is very important piece of information for our supply chain, as it provides information on the freshness of apple. You can store any other information you find important.

Before we start the implementation start the ipfs server using the command ipfs daemon.

ipfs daemon

IPFS using python

import ipfshttpclient
import json
import sys

We can add data to IPFS in three simple steps. First, creating a connection to IPFS server using “/dns/”. The second step is to collect the metadata which is taken from the user. The colour and date entered by the user are converted to the JSON format.

The final step is to add data to the IPFS server. We can do that using add_json function.

Now, the major task left is to integrate our python script with the smart contract, I created in a previous blog. Before that, we have to interact with the smart contract using web3.js.

const Web3 = require('web3',3000)

We can now interact with the apple smart contract using the ‘apples’ object. For example, we need to call the _mint function of the apple smart contract, we can use apples._mint(address). To call python script from script we will use child_process module. Make sure you import the child_process using const { spawn } = require(‘child_process’) in the node.js file.

web3.eth.defaultAccount = minterAddress;


You now know, how we can store metadata for a product on the IPFS. We can create a front-end using HTML or React and create a complete distributed application for an apple supply chain.

In a previous blog, I had shared how we can use blockchain technology in supply chain, using an apple use case. If you haven’t read it, find it here.


A Software Development Company