Hosting Dapps using IPFS

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.

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

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

ipfs object get  
 
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.

dnslink=/ipfs/<hash> 
 
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.  

 
 


Comments

Popular Posts