So you want to start coding blockchain? … IPFS & OrbitDB [4.1]

In the previous posts we have gone through several steps in learning how to code blockchain.

  • Step 0: describes how efficient are the modern development tools, with a hands-on example to code and deploy your own web server and its client in only 10 lines of code.

We continue this journey here with IPFS and OrbitDB, through a short JavaScript application. In the same approach as in Step 0, this application shows how to leverage existing powerful libraries to create and use a peer-to-peer decentralised database with only a few lines of code.

What will we learn today?

Instead of proceeding chronologically, the plan of this tutorial innovates as follows:

  • We start with explaining the code itself, in case you have already done the steps above and have your development environment.

The application (kind of) “Hello World” storyboard

The code

  • First, install the relevant npm packages. For this, navigate to in your working directory and in your console (Terminal on MacOS), type this command: npm install ipfs-http-client orbit-db
  • save the file as index.js

Congratulations. You have spawned an IPFS node, created a peer-to-peer key-value database, written 2 entries and read them back. That’s all folks.

What have you done?

  • You have installed 2 JavaScript packages to use IPFS and OrbitDB. The ipfs package includes a daemon that can be called from the command line to create an IPFS peer client

You may want to pursue and read more about IPFS and OrbitDB and see how their design differ from legacy databases.

Explanation of the code

  • line 6 imports the package ipfs.

Reminder: how to install your development environment

Setup instructions for MacOS

  • Install Brew

Setup instructions for Linux Ubuntu

curl -fsSL | sudo -E bash -
sudo apt-get install -y nodejs

Under Windows, it is strongly recommended to run a VirtualBox for Windows and install a Ubuntu Virtual Machine inside it. Here is a YouTube video of 4 minutes, that can guide you through this double installation process:

Next step: how to design a peer-to-peer decentralised database using IPFS & OrbitDB

See the second part here:

Machu Picchu — Data as a Public Service

Machu Picchu — Data as a Public Service