5-minute Tut: Using IPFS to host your Dapp

Considering you're reading this blog post, I'm going to assume you know what IPFS is, or at least heard of it.
Maybe one of your colleagues dropped the name, or some random chap on the internet told you to put your website or decentralized application on IPFS.

Nevertheless, I won't be going into detail than what is strictly necessary to host some simple static files on IPFS. It's an introduction aimed at beginners who want to tinker around with the distributed web.

What is IPFS?

IPFS stands for InterPlanetary File System. It's a protocol designed to create a permanent and fully decentralized method to store and share files.

It aims to be a replacement for the http-protocol, but faster, more efficient and less expensive. IPFS makes it possible to distribute high volumes of data with high efficiency and zero duplication means less storage cost.

It's a peer-to-peer distributed file system, has no single point of failure and nodes do not need to trust eachother.

IPFS is highly resilient and provides historic versioning. Think of it as git for the world wide web.

Why use IPFS to host your DApps?

If you want to deliver a decentralized application, you might just be thinking about a decentralized backend. Leveraging blockchain technology as the backbone of your applications will deliver decentralized, open and highly resilient solutions. But it's important that not only your backend is highly resilient.

You might be relying on a single webserver, configured with apache or simply an s3 bucket with cloudfront or a github page with an Akamai cache. These solutions work great and will be the perfect safe haven for your day-to-day development.

But you're creating a DApp. A Decentralized Application. You want more.

5 minute tutorial

First of all, before being able to push your files to IPFS, you'll need to install it.

Download the binary flavor you need for your environment.

tar xvzf go-ipfs.tar.gz  
mv  go-ipfs/ipfs /usr/local/bin/ipfs  

You can test your installation by running:

ipfs help  

Now that you have IPFS on your machine, you can push files to it. Pushing files will add them to the network and return you a hash. Navigate to the folder whose contents you wish to upload and enter:

ipfs add -r .  

This will add the folder to IPFS recursively, making sure all references are linked. The last hash returned is the hash of the folder, which is the one we'll need later.

If you wish to upload just a single file, type

ipfs add <file>  

You can see the metadata of the object linked to any hash by typing

ipfs object get <hash>  

To see our file in our browser, we'll need to start up an ipfs daemon, which you will need to be able to communicate. This command make you a node on the network and will start up a gateway. Open up a new terminal and enter:

ipfs daemon  

Now navigate to http://localhost:8080/ipfs/hash to see your folder being served over http. You can also navigate to https://ipfs.io/ipfs/hash to see your files being served over another node. It might take a little bit to load your files the first time, as the files still need to propagate over the network until they're resolved by the gateway.

Extra: using DNS to point to your IPFS

We're going to throw in a something extra here, because we're still stuck with hashes, which can be found unappealing. Luckily, it is possible to enable your dns to point to an IPFS record.

First of all, you'll need to point your domain to the ip-address of https://ipfs.io. Fetch the IP and change your dns-tables to point all traffic to it.

The last thing you'll need to add is a TXT-record in your domain settings which the IPFS gateway can check and serve the correct page. Enter the hash we saved earlier in the hash field.


That's it, you're all set. If you navigate to your domain now, you'll be presented with the page you uploaded to IPFS.

Comment below on what applications you've been deploying on IPFS and share your experiences with me.


comments powered by Disqus