5 min read

This article is an excerpt taken from the book Hands-On IoT Solutions with Blockchain written by Maximiliano Santos and Enio Moura. In this book, you’ll learn how to work with problem statements and learn how to design your solution architecture so that you can create your own integrated Blockchain and IoT solution.

In this article, you will learn how to install your own blockchain network using Hyperledger Fabric and Composer.

We can install the blockchain network using Hyperledger Fabric by many means, including local servers, Kubernetes, IBM Cloud, and Docker. To begin with, we’ll explore Docker and Kubernetes.

Setting up Docker

Docker can be installed using information provided on https://www.docker.com/get-started.

Hyperledger Composer works with two versions of Docker:

  • Docker Composer version 1.8 or higher
  • Docker Engine version 17.03 or higher

If you already have Docker installed but you’re not sure about the version, you can find out what the version is by using the following command in the terminal or command prompt:

docker –version

Be careful: many Linux-based operating systems, such as Ubuntu, come with the most recent version of Python ( Python 3.5.1). In this case, it’s important to get Python version 2.7. You can get it here: https://www.python.org/download/releases/2.7/.

Installing Hyperledger Composer

We’re now going to set up Hyperledger Composer and gain access to its development tools, which are mainly used to create business networks. We’ll also set up Hyperledger Fabric, which can be used to run or deploy business networks locally. These business networks can be run on Hyperledger Fabric runtimes in some alternative places as well, for example, on a cloud platform.

Make sure that you’ve not installed the tools and used them before. If you have, you’ll them using this guide.

Components

To successfully install Hyperledger Composer, you’ll need these components ready:

  • CLI Tools
  • Playground
  • Hyperledger Fabric
  • An IDE

Once these are set up, you can begin with the steps given here.

Step 1 – Setting up CLI Tools

CLI Tools, composer-cli, is a library with the most important operations, such as administrative, operational, and developmental tasks. We’ll also install the following tools during this step:

  • Yeoman: Frontend tool for generating applications
  • Library generator: For generating application assets
  • REST server: Utility for running a REST server (local)

Let’s start our setup of CLI Tools:

  1.  Install CLI Tools:
npm install -g composer-cli@0.20
  1. Install the library generator:
npm install -g generator-hyperledger-composer@0.20
  1. Install the REST server:
npm install -g composer-rest-server@0.20

This will allow for integration with a local REST server to expose your business networks as RESTful APIs.

  1. Install Yeoman:
npm install -g yo

Don’t use the su or sudo commands with npm to ensure that the current user has all permissions necessary to run the environment by itself.

Step 2 – Setting up Playground

Playground can give you a UI in your local machine if using your browser to run Playground. This will allow you to display your business networks, browse apps to test edit, and test your business networks.

Use the following command to install Playground:

npm install -g composer-playground@0.20

Now we can run Hyperledger Fabric.

Step 3 – Hyperledger Fabric

This step will allow you to run a Hyperledger Fabric runtime locally and deploy your business networks:

  1. Choose a directory, such as ~/fabric-dev-servers.
  2. Now get the .tar.gz file, which contains the tools for installing Hyperledger Fabric:
mkdir ~/fabric-dev-servers && cd ~/fabric-dev-servers

curl -O https://raw.githubusercontent.com/hyperledger/composer-tools/master/packages/fabric-dev-servers/fabric-dev-servers.tar.gz
tar -xvf fabric-dev-servers.tar.gz

You’ve downloaded some scripts that will allow the installation of a local Hyperledger Fabric v1.2 runtime.

  1. To download the actual environment Docker images, run the following commands in your user home directory:
cd ~/fabric-dev-servers
export FABRIC_VERSION=hlfv12
./downloadFabric.sh

Well done! Now you have everything required for a typical developer environment.

Step 4 – IDE

Hyperledger Composer allows you to work with many IDEs. Two well-known ones are Atom and VS Code, which both have good extensions for working with Hyperledger Composer.

Atom lets you use the composer-atom plugin (https://github.com/hyperledger/composer-atom-plugin) for syntax highlighting of the Hyperledger Composer Modeling Language. You can download this IDE at the following link: https://atom.io/. Also, you can download VS Code at the following link: https://code.visualstudio.com/download.

Installing Hyperledger Fabric 1.3 using Docker

There are many ways to download the Hyperledger Fabric platform; Docker is the most used method. You can use an official repository. If you’re using Windows, you’ll want to use the Docker Quickstart Terminal for the upcoming terminal commands.

If you’re using Docker for Windows, follow these instructions:

  1. Consult the Docker documentation for shared drives, which can be found at https://docs.docker.com/docker-for-windows/#shared-drives, and use a location under one of the shared drives.
  2. Create a directory where the sample files will be cloned from the Hyperledger GitHub repository, and run the following commands:
$ git clone -b master https://github.com/hyperledger/fabric-samples.git
  1. To download and install Hyperledger Fabric on your local machine, you have to download the platform-specific binaries by running the following command:
$ curl -sSl https://goo.gl/6wtTN5 | bash -s 1.1.0

The complete installation guide can be found on the Hyperledger site.

Deploying Hyperledger Fabric 1.3 to a Kubernetes environment

This step is recommended for those of you who have the experience and skills to work with Kubernetes, a cloud environment, and networks and would like an in-depth exploration of Hyperledger Fabric 1.3.

Kubernetes is a container orchestration platform and is available on major cloud providers such as Amazon Web Services, Google Cloud Platform, IBM, and Azure. Marcelo Feitoza Parisi, one of IBM’s brilliant cloud architects, has created and published a guide on GitHub on how to set up a Hyperledger Fabric production-level environment on Kubernetes.

The guide is available at https://github.com/feitnomore/hyperledger-fabric-kubernetes.

If you’ve enjoyed reading this post, head over to the book, Hands-On IoT Solutions with Blockchain to understand how IoT and blockchain technology can help to solve the modern food chain and their current challenges.

Read Next

IBM announces the launch of Blockchain World Wire, a global blockchain network for cross-border payments

Google expands its Blockchain search tools, adds six new cryptocurrencies in BigQuery Public Datasets

Blockchain governance and uses beyond finance – Carnegie Mellon university podcast


Subscribe to the weekly Packt Hub newsletter. We'll send you the results of our AI Now Survey, featuring data and insights from across the tech landscape.