Hyperledger Composer Development Environment


Hyperledger Composer Development Environment

Recipe ID: hsts-r15


Self-paced training

We offer blockchain introduction, Hyperledger for system admin, Ethereum, Solidity, Corda R3, Hyperledger for developers, blockchain cybersecurity and more classes in self-paced video format starting at $60. Click here to learn more and register. For complete self-paced blockchain training, visit our Complete Blockchain Development Training page.


Recipe Overview

A development environment consists of all Composer tools and networks that are required in order to start building Hyperledger Composer. This is not a hard task. The Hyperledger Composer can run on various operation systems including Unix (Ubuntu), macOS, or Windows. In this recipe, we will cover Ubuntu.

For those who are not familiar with Hyperledger project, reading Blockchain Overview, Intro to Hyperledger Family and Hyperledger Blockchain Ecosystem, Hyperledger Design Philosophy and Framework Architecture, Overview of Building Blockchain Smart Contracts in Hyperledger and The Survey of Hyperledger Fabric Architecture and Components for Blockchain Developers articles are strongly recommended beforehand.

In this recipe, we will cover setting up the Hyperledger Composer prerequisites & development environment. In our previous recipe, we discussed the Hyperledger Composer Business Network And Development Components and after this recipe, we put different pieces together by Configuring a Hyperledger Composer Business Network.

Prerequisite Components and Installation

Before we set up a development environment, make sure you have installed the following prerequisites:

To run Hyperledger Composer and Hyperledger Fabric, 4 GB of memory are required. If you are running an Ubuntu system on VirtualBox, the system needs at least 12-16 GB.

Here, we are using Amazon Ubuntu Server 16.04 as our choice of OS. If you don't have experience with installing Ubuntu in EC2, please refer to the following AWS document:
https://aws.amazon.com/getting-started/tutorials/launch-a-virtual-machine/

You can also install Ubuntu in your local machine VirtualBox. A tutorial for this can be found at http://www.psychocats.net/ubuntu/virtualbox and https://askubuntu.com/questions/142549/how-to-install-ubuntu-on-virtualbox

Once you have installed Ubuntu, log on to Unix and you can download and run the prerequisites from the Hyperledger GitHub site using the following commands:

curl -O https://hyperledger.github.io/composer/latest/prereqs-ubuntu.sh chmod u+x prereqs-ubuntu.sh
./prereqs-ubuntu.sh
With the sudo command, you will be prompted for your password:

Once installation is done, you need to log out and log on again to make all changes take effect.
You may have noticed that prereqs-ubuntu.sh includes a series command to install all the required libraries. Docker provides a container environment to run the tests and to run HyperLedger Fabric. Docker Compose is used to easily configure and start HyperLedger Fabric. Node.js and npm provide the main runtime environment by handling package management and dependency installation. If you're running on Ubuntu Trusty, it is necessary to obtain additional kernel packages to enable the use of the AUFS storage driver for Docker.

Setting up the Development Environment
Composer-CLI is the most important tool for Composer deployment; it contains all the essential command-line operations. Other very useful tools include Composer REST server, generator Hyperledger Composer, Yeoman, and Playground. Composer CLI provides many useful tools for developers; we will be using it in this recipe.
Composer CLI can be used to perform multiple administrative, operational, and development tasks. Here is a summary of the CLI commands:


Command

Description

Examples

composer archive

<subcommand>

Composer archive command.

 

Composer archive list.

 

composer card

<subcommand>

Command for managing business

network cards.

Composer card list.

 

composer generator

<subcommand>

 

Composer generator command to

convert a business network

definition into code.

Composer generator

docs.

 

composer identity

<subcommand>

Composer identity command.

 

Composer identity

issue.

composer network

<subcommand>

Composer network command.

 

Composer network

install.

composer participant

<subcommand>

Composer participant command.

Composer participant

add.

composer report

 

 

Command for creating a report of

the current .Composer

environment

 

Composer report.

 

composer transaction

<subcommand>

Composer transaction command.

 

 

Composer transaction

submit.

The Composer REST server is used to generate a REST interface to a deployed blockchain business network.

In the previous step, we installed all the required libraries. If you haven't done this, please complete the previous setup. Now you can continue with the following installation:

docker kill $(docker ps -q)

docker rm $(docker ps -aq)

docker rmi $(docker images dev-* -q)

Hyperledger Composer, Playground & Hyperledger Fabric Installation

1. Install the following CLI tools:
npm install -g composer-cli@0.19.15
npm install -g composer-rest-server@0.19.15
npm install -g generator-hyperledger-composer@0.19.15 npm install -g yo

2.  Install Playground:
npm install -g composer-playground@0.19

3. Set up your IDE. Download the VSCode from https://code.visualstudio.com/download and install it using the instructions provided onscreen.

             4. Install the Composer extension. Open the VSCode extensions menu, find the Hyperledger Composer extension from the EXTENSIONS: MARKETPLACE, and then install it:

5. Install Hyperledger Fabric:
Create a directory named ~/fabric-dev-servers and download the fabric-dev-servers.tar.gz file:

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

cd ~/fabric-dev-servers

export FABRIC_VERSION=hlfv11

./downloadFabric.sh

6. We have set up the typical developer environment for Hyperledger Composer. To start the development Composer application, we should be able to start and stop our Fabric runtime. When you start up a Fabric runtime for the first time, you'll need to run startFabric.sh by generating a PeerAdmin card:

cd ~/fabric-dev-servers
export FABRIC_VERSION=hlfv11

./startFabric.sh
./createPeerAdminCard.sh

7. To stop the Fabric runtime, run stopFabric.sh and then ~/fabric-dev-servers/teardownFabric.sh to clean up the runtime environment

8. To start up Playground, run the following command:
composer-playground

9. Bring up the Playground page by entering: http://localhost:8080/login or http://yourserverIP:8080/login.

Make sure your server port number, 8080, isn't blocked (if run on the cloud server).


Put Things Together

The application uses the Hyperledger Composer LoopBack connector to connect to the business network, extract the models, and then model related REST APIs in the pages. Here is some code logic:

if (require.main === module) {
const composerConfig = require('./composer.json'); module.exports(composerConfig)
.then((result) => {
// Start the LoopBack application.
const app = result.app, server = result.server; return server.listen(() => {
app.emit('started');
let baseUrl = app.get('url').replace(/\/$/, ''); console.log('Web server listening at: %s', baseUrl); if (app.get('loopback-component-explorer')) {
let explorerPath = app.get('loopback-component-explorer').mountPath;
console.log('Browse your REST API at %s%s', baseUrl,
explorerPath);
}……

}
});
})
.catch((error) => {…
});
}

generator-hyperledger-composer is used to create pro-forma templates for use with the Hyperledger Composer.

Yeoman provides the generator-hyperledger-composer utility tool to generate applications.

Hyperledger Composer Playground is a browser-based user interface that makes it possible to configure, deploy, and test a business network. You can use the Playground to model your business network, including defining assets, participants, ACL, and transactions involved in the process. 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.

In Hyperledger Composer, it installed a sample Hyperledger Fabric network (v1.0). PeerAdmin is the administrator for this network. It has admin rights to all peers in the network. You can access PeerAdmin by creating a PeerAdmin business network card.

Congratulation! We have successfully learned how to setup Hyperledger Composer prerequisites & development environment. The next step is to Configure a Hyperledger Composer business network.

The following recipes are excellent resources for installing other Hyperledger tools:

Blockchain Developer Guide- How to Install Hyperledger Fabric on AWS
Blockchain Developer Guide- How to Install and work with Hyperledger Sawtooth
Blockchain Developer Guide- How to Install Hyperledger Burrow on AWS
Blockchain Developer Guide- How to Install Hyperledger Iroha on AWS
Blockchain Developer Guide- How to Install Hyperledger Indy and Indy CLI on AWS
Blockchain Developer Guide- How to Install Hyperledger Seth and Docker on AWS

To conclude this recipe, we like to recommend our Blockchain Hyperledger Development in 30 hours course to those interested in pursuing a blockchain development career. Indeed, as of this writing, Hyperledger Foundation offers the following two Hyperledger certifications: The Certified Hyperledger Fabric Administrator (CHFA) and The Certified Hyperledger Sawtooth Administrator (CHSA), both of which are highly regarded in the industry. Hyperledger Foundation is in the process of creating Hyperledger Developer certification program, which may be released in early or middle of 2020. In short, by taking our hands-on online Hyperledger class, you would be able to obtain CHFA certification.
This recipe is written by Brian Wu who is our senior Hyperledger instructor in Washington DC. His Hyperledger Cookbook with 40+ hands-on recipes is highly recommended.

Related Training Courses

Hands-on Node.JS, MongoDB and Express.js Training
Advance JavaScript, jQuery Using JSON and Ajax
Learn Hands-on Blockchain Ethereum Development & Get Certified in 30 Hrs
Learn Blockchain Hyperledger Development & Get Certified in 30 Hrs
Become Blockchain Certified Security Architect in 30 hours
Blockchain Certified Solution Architect in 30 hours
Introduction to Python Programming
Object Oriented Programming with UML


Private and Custom Coding Classes

We offer private coding classes for beginners online and offline (at our Virginia site) with custom curriculum for most of our classes for $59 per hour online or $95 per hour in virginia. Give us a call or submit our Private Coding Classes for Beginners form to discuss your needs.


View Other Classes!