Note

If you are new to the blockchain technology, taking our Introduction to Blockchain Technology self-paced course is highly recommended. Also, for a comprehensive coverage of blockchain development in Ethereum or mastering Solidity programming, taking our below self paced courses is highly recommended:

Recap

In our previous article (How to Work with Ethereum Swarm Storage), we discussed how to work with Ethereum Swarm storage.

In this article, we learn how to install Ethereum Swarm storage.

Installing Swarm

To start a Swarm instance, we need to install both Geth and Swarm on our machine. We will use Ubuntu as our installation environment. The Geth tool is the Go Ethereum standalone client written in the Go language. Geth is an Ethereum client node, and it can verify the block broadcast onto the network. Geth is also responsible for maintaining your local copy of Ethereum’s network state.

The simplest way to install Swarm is via the built-in launchpad PPAs (Personal Package Archives):

1. Enable our launchpad repository and run the following command:

sudo apt-get install  software-properties-common sudo add-apt-repository -y ppa:ethereum/ethereum

2. The following command will help you install a stable version of Swarm:

sudo apt-get update
  sudo apt-get  install ethereum-swarm

3. Once installed successfully, verify the Swarm version. It will look like this:

 Ethereum blockchain development in Infura

 

One-to-One Live Blockchain Classes

Coding Bootcamps school offers One-to-One Live Blockchain Classes for Beginners.

 

Next, we will install Geth. Similar to the Swarm installation, we will install Geth on Ubuntu via PPAs.

Installing Geth

Perform the following steps to install Geth:

1. Enable our launchpad repository and run the following command:

sudo add-apt-repository -y ppa:ethereum/ethereum

2. Install the stable version of Geth with the following command:

sudo apt-get update
  sudo apt-get  install Ethereum

3. Once installed successfully, verify the Geth version. It will look like this:

 Ethereum blockchain development in Infura

 

Now that Geth and Swarm have been installed, we can run a Swarm example. Let’s do it!

Running an example of Swarm

We just installed Swarm and Geth. To start Swarm, we need an Ethereum account. Use the Geth command-line tool to create a new account, as shown in the following code:

geth account new

The Terminal will prompt for a password, so enter a password. After that, the console will display this new Ethereum account address. Here is the result:

 Ethereum blockchain development in Infura

 

We will use this Ethereum account to connect with the Swarm node. To connect to Swarm, use the newly generated Ethereum account and run the following command:

$ swarm -bzzaccount 6e7782893d4957f4eb2a4fcd9350b68f1fbf81f558ca84debcd0c8bed7ea122b

Replace the hash with your account address key when you run the example. Here is the result:

 Ethereum blockchain development in Infura

 

Swarm is fully integrated with the Geth console. To bring up the Swarm Geth console, open another new Terminal and run the Geth command in the console, as follows:

geth attach  $HOME/.ethereum/bzzd.ipc

You will get a result that’s similar to the following:

 Ethereum blockchain development in Infura

 

Once Swarm is running, we can start uploading files to the network. Here, we will use a simple text file that contains Hello Swarm and upload it to Swarm:

 ubuntu@ip-172-31-41-161:~$  swarm up learn-ethereum.txt 6e7782893d4957f4eb2a4fcd9350b68f1fbf81f558ca84debcd0c8bed7ea122b

As shown in the preceding code block, the console returns the hash key of the uploaded file. The hash is the access-controlled manifest.
You can access the uploaded files through the local HTTP gateway on port 8500, as shown here, at http://localhost:8500/bzz:/<file_hash>:

 Ethereum blockchain development in Infura

 

Alternatively, you can access the file through Swarm’s public gateway at http://swarm- gateways.net/bzz:/<file_hash>.
Here is a screenshot showing Swarm being accessed using the HTTPS Swarm public gateway:

 Ethereum blockchain development in Infura

 

Now we’ve explored the two most popular decentralized storages—IPFS and Swarm. I am sure you feel comfortable with the concept of decentralized storage now. In the next section, we will discuss an exciting topic: decentralized messages with Whisper.

 

Next Article
In our next article (How to Handle Ethereum Messages with Whisper), we discuss how to process Ethereum messages with Whisper.

This article is written in collaboration with Brian Wu who is a leading author of “Learn Ethereum: Build your own decentralized applications with Ethereum and smart contracts” book. He has written 7 books on blockchain development.

Resources

Free Webinars on Blockchain

Here is the list of our free webinars that are highly recommended:

 

Free Courses

Here is the list of our 10 free self-paced courses that are highly recommended:

 

Self-Paced Blockchain Courses

If you like to learn more about Hyperledger Fabric, Hyperledger Sawtooth, Ethereum or Corda, taking the following self-paced classes is highly recommended:

  1. Intro to Blockchain Technology
  2. Blockchain Management in Hyperledger for System Admins
  3. Hyperledger Fabric for Developers
  4. Intro to Blockchain Cybersecurity
  5. Learn Solidity Programming by Examples
  6. Introduction to Ethereum Blockchain Development
  7. Learn Blockchain Dev with Corda R3
  8. Intro to Hyperledger Sawtooth for System Admins

 

Live Blockchain Courses

If you want to master Hyperledger Fabric, Ethereum or Corda, taking the following live classes is highly recommended:

 

Articles and Tutorials on Blockchain Technology

If you like to learn more about blockchain technology and how it works, reading the following articles is highly recommended:

 

Articles and Tutorials on Ethereum and Solidity

If you like to learn more about blockchain development in Ethereum with Solidity, reading the following articles and tutorials is highly recommended:

 

Articles and Tutorials on Hyperledger Family

If you like to learn more about blockchain development with Hyperledger, reading the following articles and tutorials is highly recommended:

 

Articles and Tutorials on R3 Corda

If you like to learn more about blockchain development on Corda , reading the following articles and tutorials is highly recommended:

 

Articles and Tutorials on Other Blockchain Platforms

If you like to learn more about blockchain development in other platforms, reading the following articles and tutorials is highly recommended: