Installing IPFS

We will start by installing IPFS locally on our machine, which will give us the tools required to upload and view content on the IPFS network. Installation processes will vary depending on your machine's architecture—full instructions can be found at https://ipfs.io/docs/install/.

Once IPFS has been installed, we can initialize our node as follows:

ipfs init

Once this has completed correctly, the following output will displayed:

initializing ipfs node at /Users/jbenet/.go-ipfs
generating 2048-bit RSA keypair...done
peer identity: Qmcpo2iLBikrdf1d6QU6vXuNb6P7hwrbNPW9kLAH8eG67z
to get started, enter:

ipfs cat /ipfs/QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv/readme

Run the suggested ipfs cat command to read a welcome file:

Hello and Welcome to IPFS!

██╗██████╗ ███████╗███████╗
██║██╔══██╗██╔════╝██╔════╝
██║██████╔╝█████╗ ███████╗
██║██╔═══╝ ██╔══╝ ╚════██║
██║██║ ██║ ███████║
╚═╝╚═╝ ╚═╝ ╚══════╝

If you're seeing this, you have successfully installed
IPFS and are now interfacing with the ipfs merkledag!

-------------------------------------------------------
| Warning: |
| This is alpha software. Use at your own discretion! |
| Much is missing or lacking polish. There are bugs. |
| Not yet secure. Read the security notes for more. |
-------------------------------------------------------

Check out some of the other files in this directory:

./about
./help
./quick-start <-- usage examples
./readme <-- this file
./security-notes

We've now initialized our node, but we haven't yet connected to the network. To do so, we can run the following command:

ipfs daemon

To check that we are connected correctly, we can view the nodes in the network that we're directly connected to, as follows:

ipfs swarm peers

Having connected to the network, it will now be possible to access the documents stored and distributed by it. To test whether we can do this, we'll use a test file that already resides on the network.

In this case, it's an image of a cat, and, because it's an image file, we'll first need to direct the data to a new file for viewing:

ipfs cat /ipfs/QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ/cat.jpg >cat.jpg

This is perhaps a confusing example: we're using the ipfs cat command to show an object stored in IPFS, where the object itself is a picture of a cat, named cat.jpg.

As well as accessing the file directly, the file can also be viewed by using any of the following options:

  • The local IPFS gateway that is run by our client, on port 8080:
curl "http://127.0.0.1:8080/ipfs/QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ/cat.jpg" > local_gateway_cat.jpg
  • A remote public IPFS gateway URL:
curl "https://ipfs.io/ipfs/QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ/cat.jpg" > public_gateway_cat.jpg

Now that our local client is running correctly, and we are able to interact with the network, we can move on to adding files and directories.

The simplest way to add a single file is to use the following command, passing it the path to the file that you want to upload:

ipfs add <file>

Running this command returns a hash, which is used as the file's IPFS address. This address is based on the contents of the file, and can be used to access the file, as shown previously.

We'll return to adding files later, when we add the files associated with our ICO website to the network.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset