Setting up your Hyperledger Composer

Ajay Yadav
4 min readFeb 21, 2019

Step1: Installing pre-requisites

To run Hyperledger Composer and Hyperledger Fabric, we recommend you have at least 4Gb of memory.

The following are prerequisites for installing the required development tools:

• Operating Systems: Ubuntu Linux 14.04 / 16.04 LTS (both 64-bit)

• Docker Engine: Version 17.03 or higher

• Docker-Compose: Version 1.8 or higher

• Node: 8.9 or higher (note version 9 and higher is not supported)

• npm: v5.x

• git: 2.9.x or higher

• Python: 2.7.x

• A code editor of your choice, I used VSCode.

**If installing Hyperledger Composer using Linux, be aware of the following advice:

• Login as a normal user, rather than root.

• Do not su to root.

• When installing prerequisites, use curl, then unzip using sudo.

• Run prereqs-ubuntu.sh as a normal user. It may prompt for root password as some of it’s actions are required to be run as root.

• Do not use npm with sudo or su to root to use it.

• Avoid installing node globally as root.**

If you’re running on Ubuntu, you can download the prerequisites using the following commands:

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

chmod u+x prereqs-ubuntu.sh

Next run the script — as this briefly uses sudo during its execution, you will be prompted for your password

./prereqs-ubuntu.sh

Step2: Installing the Development Environment

Install the CLI tools

1. Essential CLI tools:

npm install -g composer-cli@0.20 (This is latest right now)

2. Utility for running a REST Server on your machine to expose your business networks as RESTful APIs

npm install -g composer-rest-server@0.20 (This is latest right now)

3. Useful utility for generating application assets:

npm install -g generator-hyperledger-composer@0.20

4. Yeoman is a tool for generating applications, which utilises generator-hyperledger-composer:

npm install -g yo

Step 3: Set up your IDE

Step 4: Install Hyperledger Fabric

This step gives you a local Hyperledger Fabric runtime to deploy your business networks to.

1. In a directory of your choice (we will assume ~/fabric-dev-servers), get the .tar.gz file that contains the tools to install 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

A zip is also available if you prefer: just replace the .tar.gz file with fabric-dev-servers.zip and the tar -xvf command with a unzip command in the preceding snippet.

Use the scripts you just downloaded and extracted to download a local Hyperledger Fabric v1.2 runtime:

cd ~/fabric-dev-servers

export FABRIC_VERSION=hlfv12

./downloadFabric.sh

Step 5: Controlling your dev environment

Starting and stopping Hyperledger Fabric

You control your runtime using a set of scripts which you’ll find in ~/fabric-dev-servers if you followed the suggested defaults.

The first time you start up a new runtime, you’ll need to run the start script, then generate a PeerAdmin card:

cd ~/fabric-dev-servers

export FABRIC_VERSION=hlfv12

./startFabric.sh

./createPeerAdminCard.sh

You can start and stop your runtime using

~/fabric-dev-servers/stopFabric.sh

To Tear Down the Network run the command

~/fabric-dev-servers/teardownFabric.sh.

Note that if you’ve run the teardown script, the next time you start the runtime, you’ll need to create a new PeerAdmin card just like you did on first time startup.

Step 6: Create Your Bussiness Network Definition

The Business Network Definition is a key concept of the Hyperledger Composer programming model. They are represented by the BusinessNetworkDefinition class, defined in the composer-common module and exported by both composer-admin and composer-client.

Model.cto: Define the structure and relationship between model elements.
Contains: Assests, Participants and Transaction definitions

Script File .js : This file contains the transaction function.

Access Control .acl : This file defines the set of acess control rules which define the right of different participants in the network.

Query File .qry: Name, version etc of Bussiness Network.

Once these all files defined we run the given command to create the .bna file which is to be deployed on the network

composer archive create -a <business-network-archive>

Step 7: Deploying Business Networks

Once the business network archive file has been created it can be deployed to Hyperledger Fabric using the composer network install command followed by a composer network start command.

composer network install — archiveFile tutorial-network@1.0.0.bna — card PeerAdmin@fabric-network

composer network start — networkName tutorial-network — networkVersion 1.0.0 — card PeerAdmin@fabric-network — networkAdmin admin — networkAdminEnrollSecret adminpw

My Network For Single Organisation and Single Orderer

The Hyperledger Fabric network is made up of several components:

• A single peer node for Org1, named peer0.org1.example.com.

• The request port is 7051.

• The event hub port is 7053.

• A single Certificate Authority (CA) for Org1, named ca.org1.example.com.

• The CA port is 7054.

A single orderer node, named orderer.example.com.

• The orderer port is 7050.

--

--