Please follow and like us:

If you need to experience BTFS using web-based tool, visit bitseed.net. You can upload file to BTFS network there

Create a simple static site

All you need is a simple static HTML page, as long as ALL the links are relative. For the purposes of this tutorial, I have put a simple hello world here

Save these files in a folder named site.

Add to BTFS

Next, you need to add the site to BTFS.

$ btfs add -r site/

You should see something like this:

added QmaL9R8Mxpgn7gxiqYytccM3BWX1FZfSRNGPJChu62Xe2B site/index.html
added QmazEzEvcnQ6QRdMCMYPMFphen85G93x7qKpxgeCH2FFmu site/style.css
added QmeYMHYf9Sor9q8aUgHwSL466BQQ5WK12AadV7BApDEFPU site

The hash on the last line is the root of your site, you can visit is by opening http://localhost:8080/btfs/<your hash here>.
You can also view the website from the public BTFS gateway, but the website may take minutes to be available on the public gateway.

https://gateway.btfssoter.io/btfs/QmeYMHYf9Sor9q8aUgHwSL466BQQ5WK12AadV7BApDEFPU

Publish to IPNS

Now you have a simple static site hosted on BTFS. The problem is, whenever you update your site, the hash will change, and any links you have shared will continue pointing to the old version.

You need a way to always share the latest hash. That’s where IPNS comes in. It allows you to store a reference to an BTFS hash under the namespace of your peerID (hash of your public key).

If you want to know more about IPNS and How it Works, head here.

$ btfs name publish <your site hash>

This may take a few minutes. We will see how to do this faster using DNSLink below.

You will see something link this after your website has been published using IPNS.

Published to QmeYMHYf9Sor9q8aUgHwSL466BQQ5WK12AadV7BApDEFPU: /btfs/QmQToNGFsGMkQe76mRirCvRykJSiRB1JPpRLumyMN7N67T

That will return your peerID(the bold text above) and the hash you are publishing to it. You can confirm by running:

$btfs name resolve <peerId>

This will also a few minutes. After this is executed, you will see something like this:

https://gateway.btfssoter.io/btfs/QmeYMHYf9Sor9q8aUgHwSL466BQQ5WK12AadV7BApDEFPU

or you can view https://gateway.btfssoter.io/ipns/<peerID> (notice the directory is ipns not ipfs). This will also a few minutes.
After a few minutes, you will be able to see your website:

https://gateway.btfssoter.io/ipns/QmeYMHYf9Sor9q8aUgHwSL466BQQ5WK12AadV7BApDEFPU

IPNS forgets(Time to Live System) published names after about 12 hours. You might want to run a cron job to republish within 12 hours.

Please follow and like us:
How to create website on BTFS
Tagged on:         

Leave a Reply

error: Content is protected !!