Creating Application in Hyperledger

Step 1: Outline your Business Network

Our Business Network Definition (BND) consists of the data model, transaction logic, and access control rules. The data model and access control rules are coded in domain specific language (which is very simple to catch up with). The transaction logic will be coded in JavaScript.

$ yo hyperledger-composer

Step 2.1: Coding out our Business Network (models/test.cto)

First, we’ll define models/test.cto. It contains the class definitions for all assets, participants, and transactions in the business network. This file is written in .

namespace test
asset Account identified by accountId {
o String accountId
--> Customer owner
o Double balance
participant Customer identified by customerId {
o String customerId
o String firstName
o String lastName
transaction AccountTransfer {
--> Account from
--> Account to
o Double amount

Step 2.2: Coding out the Business Network (lib/logic.js)

In this file, we’ll add transaction logic in JavaScript.

* Sample transaction
* @param {test.AccountTransfer} accountTransfer
* @transaction
function accountTransfer(accountTransfer) {
if (accountTransfer.from.balance < {
throw new Error ("Insufficient funds");
accountTransfer.from.balance -= accountTransfer.amount; += accountTransfer.amount;
return getAssetRegistry('test.Account')
.then (function (assetRegistry) {
return assetRegistry.update(accountTransfer.from);
.then (function () {
return getAssetRegistry('test.Account');
.then(function (assetRegistry) {
return assetRegistry.update(;

Step 3: Generate the Business Network Archive (BNA)

Now that the business network has been defined, it must be packaged into a deployable business network archive (.bna) file.

$ composer archive create -t dir -n . 
$ composer runtime install --card PeerAdmin@hlfv1 --businessNetworkName test-bank
$ composer network start --card PeerAdmin@hlfv1 --networkAdmin admin --networkAdminEnrollSecret adminpw --archiveFile test-bank@0.0.1.bna --file networkadmin.card
$ composer card import --file networkadmin.card
$ composer network ping --card admin@test-bank

STEP 5: Expose a RESTful API

To create a RESTful API from your command line, run the following command:

$ composer-rest-server

Step 6: Angular Front End

To create Angular scaffolding automatically, run the following command in the test-bank folder:

$ yo



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store