The decentralized internet you can use right now.

Jonathan Warner
5 min readMar 2, 2021

Why do we need another internet?

The internet’s growth has been very rapid. While this has created amazing opportunities for the improvement of our world, it has also come with its downsides. The internet as it is now is easily censored, susceptible to outages and attackers, and doesn’t protect user’s data. The decentralized internet solves these problems and rethinks data ownership so that users are in full control of their data.

Today’s Centralized Internet

The internet of today is powered by warehouses of servers that hold all of our data in one central place and send that data to computers that request it using the address of the server. This is expensive and inefficient.

A Decentralized Internet

A decentralized internet runs without the massive server farms or big tech data hogs. Data on the decentralized web is broken up into many pieces and sent to other user’s computers. Later when you need to retrieve that data, those other users send that data back to you in pieces that you then reconstruct.

Here’s another way to look at it. Imagine you have a jigsaw puzzle that displays an important secret message. You need this message for later, but you don’t want others to see it so you can’t store it in the open. You decide to give one piece of the puzzle to each of your friends. Later when you need to remember the secret message you can collect the puzzle pieces from your friends and put them back together to read the message. This keeps your message safe from prying eyes.

But what if your friend loses their puzzle piece? This is a concern, but in practice you would give the same puzzle piece to many people so that if some of your puzzle pieces were lost, there would be another person with the same piece.

This is very similar to how the decentralized internet functions. If it sounds like a lot of work, you’re not wrong. Fortunately, there is a system that does all of this for us. It’s called IPFS. IPFS has a robust desktop app for managing your connection to the decentralized web.

Lets dive a little deeper.

We know the decentralized net breaks data into pieces for security, but those little pieces of data could still be dangerous in the wrong hands. This is why the pieces of data are encrypted before being distributed. This makes it very difficult for malicious actors to be able to read any piece of the data. Additionally, if they did manage to crack open the file they would still only have a small, insignificant portion of it.

Retrieving Data

When a user retrieves data from the network, they must be able to confirm that the data they receive is identical to the data that was originally uploaded. This is done by assigning a unique hash value to that data so that later it can be identified and its integrity can be verified.

Since data in a decentralized web is stored all over the world between many different peers it is important that we be able to verify data as it is received instead of having to wait until all the data has been received to verify its integrity. If we hash our data together in its entirety there is no way for us to validate smaller portions of it.

This is where Merkle Trees come to the rescue. A Merkle Tree is a tree where the leaf nodes are the hashes of pieces of data. Those hashes are combined and hashed again as we travel up the tree towards the root hash as shown in the diagram below.

https://en.wikipedia.org/wiki/Merkle_tree

By hashing our data using a Merkle Tree structure we are able to verify that an individual piece of data is a part of the whole resource we are retrieving by constructing the tree using know hashes and the hash of our received data.

Getting Started With IPFS

IPFS allows you to store data in a decentralized network of other IPFS users. To get started on the secure IPFS network, the first step is to install the IPFS desktop app. From there you can store information on the decentralized network, and you can become a node on the network that stores tiny bits of data for other people.

Use IPFS-JS to Store a String of Text

IPFS has two companion libraries to make it easier to build projects that use their network. There is a library written in Go and a library in JS. We are going to use the JS library to write a simple application to store some data in the IPFS network and then retrieve it.

First, create your node JS project folder and run:

npm install ipfs-core

Now, create an index.js file and paste this code in.

const IPFS = require('ipfs-core')

const ipfs = await IPFS.create()
const { cid } = await ipfs.add('Hello world')
console.info(cid)

This code imports ipfs, creates a new node, and adds the text, “Hello World” to the network. You can also add files or JSON using the ipfs.add() method. After the text is added to the network it prints the address that the text can be retrieved from. That address might look similar to this: “QmPChd2hVbrJ6bfo3WBcTW4iZnpHm8TEzWkLHmLpXhF68A”

Now you can retrieve that data using your address that you just received. Make sure to replace the string on line 4 with your address:

const node = await IPFS.create()const stream = node.cat('QmPChd2hVbrJ6bfo3WBcTW4iZnpHm8TEzWkLHmLpXhF68A')
let data = ''
for await (const chunk of stream) {
// chunks of data are returned as a Buffer, convert it back to a string
data += chunk.toString()
}
console.log(data)

Congratulations! You just made your first contributions to the decentralized internet of the future. I only just skimmed the surface of the world of the decentralized web and there is so much more you can learn, so get out there and build something cool with IPFS!

Citations:

Cheryl Douglass. “An Introduction to IPFS (Interplanetary File System).” Infura Blog | Tutorials, Case Studies, News, Feature Announcements, Infura Blog | Tutorials, Case Studies, News, Feature Announcements, 10 Dec. 2020, blog.infura.io/an-introduction-to-ipfs/.

“A Full P2P Protocol Written Entirely in JavaScript.” JS IPFS, js.ipfs.io/.

Labs, Protocol. “IPFS Powers the Distributed Web.” IPFS, ipfs.io/.

Ppio. “What Is Decentralized Storage?” Medium, Medium, 18 June 2019, medium.com/@ppio/what-is-decentralized-storage-9c4b761942e2.

--

--