Setup and build Hyperledger Fabric Blockchain Applications

Davor Kljajic
7 min readMay 30, 2018

The first part of this article is focused on the infrastructure layer, Hyperledger Fabric.

Official logo

The second part of this article is focused on the application layer, Fabric Composer.

The third part of this article is focused on wiring up everything such as linking to Angular Apps, Composer Playground and Importing and Managing Cards.

The Infrastructure Layer

Create server instance, recommend is minimum 16 GB.You will download the key pair and put it in some folder on your local machine.

Steps to how to set up an environment and network

Using ubuntu-xenial-16.04-amd64-server.

Install golang v1.1, node v8.9 , npm, docker, or in the next section you can install all this with script prequsition for ubunt.

sudo apt-get update
wget https://storage.googleapis.com/golang/go1.7.4.linux-amd64.tar.gz
sudo tar -xvf go1.7.4.linux-amd64.tar.gz sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
sudo apt-add-repository 'deb https://apt.dockerproject.org/repo ubuntu-xenial main'
sudo apt-get install -y docker-engine || sudo apt install docker.io
sudo curl -o /usr/local/bin/docker-compose -L https://github.com/docker/compose/releases/download/1.11.2/docker-compose-$(uname -s)-$(uname -m)
sudo chmod +x /usr/local/bin/docker-compose

Be sure to check the docker version after this phase with command docker -v.

docker_version

Install prerequisites-ubuntu

There is an automated installation script that will install node, docker-compose and npm.

curl -O https://hyperledger.github.io/composer/prereqs-ubuntu.sh

Go to the link:

https://github.com/hyperledger/composer/blob/master/packages/composer-website/jekylldocs/prereqs-ubuntu.sh

Copy the code and change the prereqs-ubuntu.sh.

nano prereqs-ubuntu.sh
chmod u+x prereqs-ubuntu.sh
./prereqs-ubuntu.sh

Let’s go back to the Fabric and his scripts.

Clone the Hyperledger Fabric

Official logo

This repository contains a number of helper scripts to start up a Hyperledger Fabric v1.1 network for development purposes. You can use the Hyperledger Fabric network created by these scripts to quickly deploy Blockchain business networks built using Hyperledger Composer, and test applications that depend on a running network.

mkdir ~/fabric-tools && cd ~/fabric-tools
curl -O https://raw.githubusercontent.com/hyperledger/composer-tools/master/packages/fabric-dev-servers/fabric-dev-servers.zip
sudo apt install unzip
unzip fabric-dev-servers.zip

Below are some important commands inside the Factory, we will not use them right now, but we will just list them.

Downloading Hyperledger Fabric

Issue from the fabric-tools directory:

$ ./downloadFabric.sh

Starting Hyperledger Fabric

Issue from the fabric-tools directory:

$ ./startFabric.sh

By default, this script will pause for 15 seconds to let Hyperledger Fabric start — on some systems this isn’t enough. If you see errors from running startFabric.sh, you can alter this value. It's controlled by a environment variable that takes a numeric value representing the number of seconds to wait.

$ export FABRIC_START_TIMEOUT=30

Stop Hyperledger Fabric

Issue from the fabric-tools directory:

$ ./stop.sh

Create Hyperledger Composer PeerAdmin card

Issue from the fabric-tools directory:

$ ./createPeerAdminCard.sh

Note: this will create a Hyperledger Composer card specifically for the use of deploying a business network either by using deploy or via install/start.

Teardown Hyperledger Fabric

Issue from the fabric-tools directory:

$ ./teardownFabric.sh
all_fabric_scripts

Fire up the local fabric

This chapter presents the created contents of the following commands and their explanation of created content.

npm install -g composer-cli
cd ~/fabric-tools
./downloadFabric.sh
./startFabric.sh
./createPeerAdminCard.sh
download_content
start_content

The ./download command is self explanatory. The startFabric.sh script will setup 1 Peer, 1 Orderer, 1 Fabric CA and 1 CouchDB, each running inside their own docker VM.

docker_content

The createPeerAdminCard.sh script will create a new directory $HOME/.composer which will contain a cards directory which contains a newly created business card, tailored for the local fabric and a client-data directory which contains a public/private key pair of files and a file containing a certificate. If you are using the Fabric 1.1 you must install composer-cli for next step. The createPeerAdminCard.sh also 'imports' the card that it just created into the local card store.

created_card

The Application Layer

You have configured and setup a VM, you have your docker containers running, your Hyperledger Fabric V1.1 blockchain infrastructure is live; now you want to model, build and deploy a business application on this network. This article will show you exactly how to wire up the application layer and the infrastructure layer. In this article i will use already created blockchain network, because it will be too long article.

In the blockchain network folder, execute this commands.

npm install -g composer-rest-server
npm install -g composer-playground
npm install -g yo
npm install -g typings
npm install -g bower
npm install -g @angular/cli
npm install -g generator-hyperledger-composer

You need to be careful when installing npm elements, especially around compatible versions. After installing a particular program, it is necessary to check the version.

Because of the length of the article I will use the network as I have already mentioned and executed the above commands. There is a typo that my college was made in word journery(journey) :).

Let’s install, start network and create the admin card and import in the network.

git clone https://github.com/dambasb/bnacomposer network install --card PeerAdmin@hlfv1 --archiveFile bna/blockchain-journery.bnacomposer network start --networkName blockchain-journery --networkVersion 0.0.1 --networkAdmin admin --networkAdminEnrollSecret adminpw --card PeerAdmin@hlfv1 --file networkadmin.cardcomposer card import --f networkadmin.cardcomposer archive list -a  bna/blockchain-journery.bna
docker with network
created_network_card
check_network_name

Composer Playground

The Hyperledger Composer Playground provides a user interface for the configuration, deployment and testing of a business network. Advanced Playground features permit users to manage the security of the business network, invite participants to business networks and connect to multiple blockchain business networks.

composer-playground
composer_playground_interface

Composer rest server

This is a simple application that prompts the user for details of a connection profile, Business Network Identifier, participant id.

To install composer rest server and angular app use generator-hyperledger-composer.

options in yeoman

The application then starts a loopback application which uses the Hyperledger Composer LoopBack Connector to connect to the Business Network, extract the models and then present a page containing the REST APIs that have been generated for the model.

Executing those APIs will then have a real effect on the business network to which the application is connected.

Terminal logs

In the browser you will see Loopback API interface.

API_interface with methods

For testing purpose we will create asset sensor, after it will be visible in the client app.

Angular app

This is angular app which is also created with generator. Before we start angular app, we must setup the composer rest server and define in enviroment variables for server ip address, default is localhost.

Hyperledger generator

Also with generator you can generate the business network and model.

generating process

In the client app, we see that created asset sensor is here. Through client app you can do CRUD on elements of business network (asset, participant) and invoke transaction in the blockchain.

dasboard

That is simple demonstration how to fast setup the whole blockchain project.In the next article focus will be creating the Hyperledger Fabric network from scratch, explanation of construct files configtx, crypto-config and docker-compose. If you have any question about blockchain, this article do not hesitate to contact me . See ya soon !

Work with us!

Beyondi offers high-quality services: Web Development and Design, Mobile Development and Design, Embedded Solutions, Blockchain Solutions, Digital Marketing, SEO, Growth and Team Augmentation? You can find more about our services on our website.

--

--