Skip to content

Getting Started with IPFS Using Windows PowerShell

IPFS

Of all the P2P solutions I've experimented with, IPFS looks the most promising, even more so than the DAT Protocol (I think it's been renamed 'Hypercore' recently). There are several reasons I've started using it: IPFS is natively supported by some mainstream Web browsers, including Opera and Brave, so that content on the network can be accessed the same way one visits a Web site after pointing the browser at a known ipfs:// address. If an IPFS/IPNS link is shared on today's social media, there's a good chance the content is readily accessible to most people without the need to install or configure anything.

Both Protocol Labs and Cloudflare provide gateways that enable IPFS content over HTTP. For users who want to share files over IPNS, there is a very simple desktop application that doesn't require expertise to get started with. Anyone planning to develop or host a Web site on the network, however, will need the command line application, and that's what I'll be covering in this post.

The second reason it looks promising is there's obviously enough commercial support behind it to make IPNS ubiquitous in the not-too-distant future.

But why should anyone use IPNS in the first place? The letters stand for 'InterPlanetary File System', and it's so-called because it's designed for nodes distributed across vast distances (for example, between Earth and Mars). The idea being that it's better to have all content propagated through a decentralised network rather than hosted on a few servers that might not be reachable. That content would then be readily available to any node on the network, regardless of the distances between them or of the quality of the infrastructure. Of course, the more nodes there are in a given area, the faster a node can retrieve whatever content.

This is a practical solution to some of the biggest problems with the current Web 2.0, aside from providing a better method of Internet communication in places where the infrastructure isn't as reliable or available. It is more resilient against censorship attempts, and it gives us more control over the information we share, if and when IPFS is used as a foundation for social networks.

Setting Up an IPFS Node in the Command Line

The command line application is called 'ipfs-go'. Once that's installed, the ipfs.exe file needs to be mapped to the 'ipfs' command in the PowerShell profile. There are guides available for creating a profile if one doesn't already exist.

With ipfs-go installed and accessible in PowerShell using the 'ipfs' command, the next step is to initialise a node:

ipfs init

Then start the server with:

ipfs daemon

The above command is the one that should be used whenever the local machine is restarted.

The node also provides a graphical interface at localhost:5001/webui.

Adding a Web Site

As it happened, I had a Web site ready, consisting of multiple files, and I published the containing directory with the following:

ipfs add -r D:\Development\IPFS-EMMA

Next to each file added there'll be a signature. The most important of these is the signature next to the directory name.

Note

When content is added to the node using this method, the files won't be listed in the GUI or the command line. This is because the content is distributed on the network as small blocks of data instead of as files.

Using IPNS

Sharing IPFS links only works when the content being shared is static (or 'immutable', as the developers call it'), since any change to the content will result in a different hash signature being generated for the containing directory. To get around this, we can use a naming service called 'IPNS', which maps the directory's hash signature to a static value (the node's public key).

The process for mapping a Web site to a static IPNS address is straightforward:

ipfs name publish /ipfs/[file or directory hash]

The output should be something like:

Published to k51qzi5uqu5dgjap5lw5i5fs7l3s5r8c8pz7ize7ssdeqv2qoafa7rxbq1rwvu: /ipfs/QmYRxqFYZ7TypJazSAPj9HepyjySV43EgyXaRz9RfU5nNx

After a few minutes, the site should be accessible through a gateway:

https://gateway.ipfs.io/ipns/k51qzi5uqu5dgjap5lw5i5fs7l3s5r8c8pz7ize7ssdeqv2qoafa7rxbq1rwvu

The following address also worked in Opera:

ipns://k51qzi5uqu5dgjap5lw5i5fs7l3s5r8c8pz7ize7ssdeqv2qoafa7rxbq1rwvu/index.html

To get the local node's address/key again:

ipfs key list -l

Probably important: The IPNS address is the public key generated during the node setup, and will be unique for every node. The private key (used for generating the public key) should be exported and backed up in case we need to host the site on another machine later on. I think this is done by copying the 'PrivKey' value in the local node's config file.

At this point, we have a Web site with a static address. But what about discoverability? There is IPFS Search, which we can use just like a clear Web search engine. Most the results are currently links to content rather than to sites, since most users would be sharing files through the desktop application.