Developing Blockchain app using Hyperledger composer [draft]

What is Hyperledger ?

Hyperledger is an umbrella project of open source blockchains by Linux Foundation focused on development of blockchain based distributed ledger

Hyperledger Umbrella

For the rest this article I will be walking through composer. Building blockchain business networks using Hyperledger composer involves working with Javascript, leveraging modern tools including node.js, npm, CLI.

Hyperledger Composer- Main Components

  1. Busniess Network Archive — Capturing the core data in a business network, including the business model, transaction logic and access control, the Business Network Archive packages these elements and deploys them to a runtime.
  2. Rest API support and integration — A loopback connector for business networks that exposes a running network as a REST API which can easily be consumed by client applications and integrate non-blockchain applications.

Some key things to keep in mind

  1. Hyperledger composer supports pluggable blockchain consensus protocols to ensure that transactions are validated according to policy by the “designated business network participants”.

2. All transactions submitted are stored on the blockchain ledger, current states of asset and participants are stored in blockchain state database

3. Transactions are stored on blockchain ledger, Current state of asset and participant are stored in blockchain state database

4. Connection Profiles — Hyperledger composer uses connection profiles, a JSON document, to define the system to connect to. These are provided by the creator of the system.

5. Identities — An identity is a digital certificate and private key which are used to transact on a business network. A single identity of a participant is stored in the business network.

6. Business Network Cards — combination of identity, a connection profile and metadata of the business network. BNCs simplify the process of connecting to a business network and extends the concept of an identity outside the business network to a wallet of identities.

7. Historian Registry — A specialized registry which records successful transactions .

8. Access Control — Access control rules allow fine-grained control over what participant have access to what assets on the business network and under what conditions. (.acl)

Lets jump into actual development.

npm install -g composer-cli
npm install -g composer-rest-server
npm install -g generator-hyperledger-composer
npm install -g yo
npm install -g composer-playground

Installing Hyperledger Fabric

curl -O -xvf fabric-dev-servers.tar.gz

Creating a Business network structure (boilerplate)

yo hyperledger-composer:businessnetwork

Open org.example.mynetwork.cto file and replace it with below model, save your changes.

namespace org.example.mynetwork
asset Commodity identified by tradingSymbol {
o String tradingSymbol
o String description
o String mainExchange
o Double quantity
--> Trader owner
participant Trader identified by tradeId {
o String tradeId
o String firstName
o String lastName
transaction Trade {
--> Commodity commodity
--> Trader newOwner

Transaction logic- open logic.js replace with below

async function tradeCommodity(trade) {
trade.commodity.owner = trade.newOwner;
let assetRegistry = await getAssetRegistry('org.example.mynetwork.Commodity');
await assetRegistry.update(trade.commodity);

Access control- Open permission.acl replace with below

* Access control rules for tutorial-network
rule Default {
description: "Allow all participants access to all resources"
participant: "ANY"
operation: ALL
resource: "org.example.mynetwork.*"
action: ALLOW

rule SystemACL {
description: "System ACL to permit all access"
participant: "ANY"
operation: ALL
resource: "org.hyperledger.composer.system.**"
action: ALLOW

Generate Business network arhive (.bna) [do not forget ‘.’ at the end]

composer archive create -t dir -n .

Deploying the Business network- this step needs PeerAdmin credentials

Composer network install

composer network install --card PeerAdmin@hlfv1 — archiveFile tutorial-network\@0.0.1.bna

Starting the business network

composer network start --networkName tutorial-network --networkVersion 0.0.1 --networkAdmin admin --networkAdminEnrollSecret adminpw --card PeerAdmin@hlfv1 --file networkadmin.card

Generating REST Server:


go to http://localhost:3000/explorer/

REST API using Loopback

Creating an Angular frontend app that runs against the REST API we created in the previous step.

yo hyperledger-composer:angular

Once the installation completes cd to angular project and run “npm start”

Angular app fires up against the REST AP at http://localhost:4200

Boooom! our first hyperledger based business network blockchain application is ready.

Start adding assets, participants and play around with transactions. ✌🏽

(to be continued….. deploying into single organization hyperledger)

Learner, thinker and Doer.