Getting Started With Hyperledger Composer

4 min readJun 7, 2018


Hyperledger composer is a framework for writing a blockchain network’s chaincode and to deploy the business network in Hyperledger Fabric. Composer comes with a lot of features built in that helps you architect you business network in a clean and efficient way.


First you’ll install the Hyperledger Fabric framework. We can make use of the fabric-dev-servers for this series. Make sure you’ve already installed Docker.

Now kill all the Docker images.

1 docker kill $(docker ps -q)
2 docker rm $(docker ps -aq)
3 docker rmi $(docker images dev-* -q)

Now run these following commands to download and unzip the fabric-tools folder. This is a script that help you to download and install the Hyperledger Fabric.

1 mkdir ~/fabric-tools && cd ~/fabric-tools2 curl -O  tools/master/packages/fabric-dev-servers/fabric-dev-servers.zip3 unzip

After downloading and un-ziping the fabric-tools you can download Fabric and setup the server.

1 cd ~/fabric-tools
2 ./
3 ./
4 ./

Now that your Fabric is running and create a peer admin and add it to the network. This admin is the one who will be able to deploy the business network that you build with composer to the Hyperledger Fabric.

Next is the composer-cli tool to do various composer task. It’s on npm and you’ll install it with below command.

1 npm install -g composer-cli

Also you can install the Yeoman generator for composer with the package generator-hyperledger-composer and you can install it with. Make sure you’ve installed the yonpm package in global scope.

1 npm install -g generator-hyperledger-composer


Since composer is a framework it comes with various components that are put together to create the business network and deploy it. There are several files that are indented to perform and hold some responsibilities in the architecture. I’ll explain the major and the mandatory ones below.

Model File (.cto)

Model file is the place where you’ll be defining all the entities of the business network. There are three major components in this which are the assets, participants, transactions. Each will be having the set of variables and it’s types. You can also built relationships between each entity.

Script File (.js)

This is the place where you’ll be defining the transaction processor functions. It’s the business logic of the blockchain application where you’ll be defining what kind of operations can be done in the network. It’s written in javascript.

Access Control File (.acl)

When you want to create user roles and define the role based validations you’ll be defining the rules in this file. You’ll be defining the conditions, who can perform what transactions, who can create what asset and more such rules.

Query file (.qry)

In the business network you can aslo perform queries to get the filtered results of assets, participants, and even transactions. It’s more like SQL but like a lite version of it.

Business Network Archive (.bna)

With all the above mentioned files, you’ll be creating an composer archive which will be later deployed as the business network in the hyperledger fabric enviroment.


Since you’ve installed the composer generator you can use that to build the skeleton of the business network and to do this, run the following command.

1 yo hyperledger-composer:businessnetwork

There will be set of questions that will help you to set up the skeleton. I assume that you’ve given the following as response and will be using them in future reference.

1 Network name : acme-network2 Namespace : org.acme

Once you create it, you’ll be getting the above mentioned files and you’re good to deploy the sample network to Hyperledger Fabric.

First create an archive (.bna) with the following command

1 composer archive create -t dir -n .

It’ll will create a file named acme-network@0.0.1.bna in the project’s root folder. You’ll be deploying this in your fabric. To do that first install the runtime and then start the network with this file.

1 composer runtime install --card PeerAdmin@hlfv1 --businessNetworkName acme-network2 composer network start --card PeerAdmin@hlfv1 --networkAdmin admin --networkAdminEnrollSecret adminpw --archiveFile acme-network@0.0.1.bna --file networkadmin.card

If you notice, here we’re using the PeerAdmin card that was created initially to deploy the network and also creating an network admin. there is network admin card created which you’ll be using for creating participants.

Before proceeding, make sure that you import the card, ping the server with that card and then export it again so that you can reuse it multiple times.

composer card import --file networkadmin.card
composer network ping --card admin@trucerts-network
composer card export --file networkadmin.card -n admin@trucerts-network

Now your network has been deployed and running in the Hyperledger Fabric. In the upcoming articles I’ll explain each of the components with more depth.

You can also use the playground to create a business network mock and export the bnafile at a later time. It’ll be much easier for you that way as you don’t have to redeploy for every change to the network.




DevOps/Cloud | 2x AWS Certified | 1x Terraform Certified | 1x CKAD Certified | Gitlab