Using IPNS

Whenever we need to update any of our ICO frontend files, the associated IPFS file hashes will change, meaning that the IPFS path that we first generated for our project will no longer equate to the most recent version of the files. This will cause the public URL to change whenever file changes are made.

To solve this problem, we can use IPNS (short for InterPlanetary Naming System), which allows us to publish a link that won't change when the underlying files are changed.

Let's publish the first iteration of the site to IPNS, using the hash of the main directory:

ipfs name publish QmQytFqNoyk8H1ZEaHe9wkGcbcUgaRbReEzurPBYRnbjNB

After a while, this will return a hash similar to the following:

Published to QmZW1zPDKUtTbcbaXDYCD2jUodw9A2sNffJNeEy8eWK3bG: /ipfs/QmQytFqNoyk8H1ZEaHe9wkGcbcUgaRbReEzurPBYRnbjNB

This shows a new hash, which is the peerID, along with the path that we are publishing to it. We can check that the peerID correctly resolves to our IPFS path, as follows:

$ ipfs name resolve QmZW1zPDKUtTbcbaXDYCD2jUodw9A2sNffJNeEy8eWK3bG
/ipfs/QmQytFqNoyk8H1ZEaHe9wkGcbcUgaRbReEzurPBYRnbjNB

The most recent version of our site will now be available at the following URL (note that we are now using ipns/ instead of ipfs/): https://ipfs.io/ipns/QmZW1zPDKUtTbcbaXDYCD2jUodw9A2sNffJNeEy8eWK3bG/.

Whenever the files of the frontend are updated, they can be published to the same IPNS path:

$ ipfs add -r dist/
$ ipfs name publish <new_directory_hash>

We can now access the most up-to-date version of our site without needing to know the updated hash associated with our changed dist/ directory.

Our IPNS hash, however, is still not very user-friendly. Therefore, the next logical step would be to bind our IPNS file path to a static domain, something which can be done by purchasing a domain and making that domain publicly known. Doing this, would require us to alter the DNS TXT record associated with our domain, to point to our IPNS URL.

There is one problem with this: it increases our reliance on centralization. Using a centralized DNS server to resolver our site's address would defeat the object of using IPFS and IPNS to begin with. For now, this isn't something that we will do.

Our site is now fully decentralized, and we have published our files on IPNS. In the next section, we will explore the equivalent operations with Swarm.