Deploying a Hyperledger Composer blockchain business network to Hyperledger Fabric.

I developed a simple Blockchain App as part of the Hackathon in India Dapp conference held at Bangalore in May 2019. The Idea was to Design a private Blockchain to Decentralize Flight information Database of the Airlines.

Private Permissioned Blockchains is the new Buzzword, With Linux Foundation’s Hyperledger project the transactional networks of today are completely revolutionized and this project has created standard methods for establishing identity on the network, executing transactions, and storing data.

All the code can be found on my Github here

Hyperledger Composer is a set of collaboration tools for building blockchain business networks that make it simple and fast for business owners and developers to create smart contracts and blockchain applications to solve business problems. Built with JavaScript, leveraging modern tools including node.js, npm, CLI and popular editors, Composer offers business-centric abstractions as well as sample apps with easy to test devops processes to create robust blockchain solutions that drive alignment across business requirements with technical development. Source

The Steps involved in making the App

Hyperledger Fabric is private and permissioned. Rather than an open permissionless system that allows unknown identities to participate in the network the members of a Hyperledger Fabric network enroll through a trusted Membership Service Provider (MSP).

Simplified Hyperledger Fabric Architecture

Setting up Development environment ==> Click

Defining Model:

Asset==> Flight details like Flight Number, Location, Working state, Flight Type, EmployeeId of the updater, Description.

Participants==> Employees responsible for updating the information.

Transaction==> Updating Location, Updater, Working state and Flight number.

To get Skeleton code and proper file structure run:

yo hyperledger-composer:businessnetwork
Model.cto

The Transaction logic is pretty simple, We are just changing the old values to new values and updating the employeeId.

logic.js

Permissions.acl is a file to assign rights and duties to the participants, peers and admins. For Simplicity I have given all the rights to Admin and System.

Then we create the Banana file(.bna) using:

composer archive create -t dir -n .

In the same directory as the above files we’ll get a airline-network@0.0.1.bna file which is used to deploy the model on the running instance of hyperledger fabric for a single organisation.

Deploying

Before continuing make sure that all the previous Network cards are removed from your wallet run: Source

rm -fr ~/.composer

We need to build a connection profile, creating a connection.json file to define and specify all of the information required to locate and connect to the Hyperledger Fabric network, for example the host names and ports of all of the Hyperledger Fabric network components.

connection.json

I’m creating a single peer(peer0.org1.example.com) the request port is 7051, Here we have specified our single CA(ca.org1.example.com) using the hostname localhost and the CA port 7054, Here, Our single orderer node (orderer.example.com) using the hostname localhost and the orderer port 7050 and we also label this as orderer.example.com. The orderers object can contain multiple orderer nodes.

I have also specified the total organisation the peers the CA the orderer and channels along with client section and the timeout length to wait before committing.

Now we look for the Private and public key of the admin which were generated after running ./startfabric.sh We then copy those keys to our project directory, And now we are ready to create our Business network card for the Hyperledger Fabric administrator.

composer card create -p connection.json -u PeerAdmin -c Admin@org1.example.com-cert.pem -k 114aab0e76bf0c78308f89efc4b8c9423e31568da0c340ca187a9b17aa9a4457_sk -r PeerAdmin -r ChannelAdmin

Next, We import the Business card into our wallet by running

composer card import -f PeerAdmin@Airline-network.card

Installing the Hyperledger Composer business network onto the Hyperledger Fabric peer nodes

composer network install -c PeerAdmin@Airline-network -a airline-network@0.0.1.bna

Starting the Blockchain

composer network start --networkName airline-network --networkVersion 0.0.1 -A admin -S adminpw -c PeerAdmin@Airline-network

When a blockchain business network is deployed, you must create at least one participant who will be a blockchain business network administrator. This participant is responsible for onboarding other participants into the blockchain business network. Here, we are specifying that we want to create a single blockchain business network administrator called admin.

-S specifies that our blockchain business network administrator admin will use an enrollment secret of adminpw to request a certificate and private key from the CA (Certificate Authority). When you specify this option, the name specified for the business network administrator must be an existing enrollment ID for a user that is already registered with the CA.

Importing the business network card for the business network administrator:

composer card import -f admin@airline-network.card

Testing:

composer network ping -c admin@airline-network
Results for Network Ping

Now we have successfully deployed blockchain business network to an instance of Hyperledger Fabric for a single organization, including generating the necessary Hyperledger Composer configuration.

Let’s generate a REST server:

composer-rest-server
REST Server configuration

NOTE: Specify if you want to enable event publication over websockets=Yes

We can Generate A skeleton Angular 4 Application:

yo hyperledger-composer:angular
Angular 4 Application
REST server and npm start

This will create a proxy to the REST server and an app.js running npm start on that folder, And ultimately serve the Angular Application on http://0.0.0.0:4200/

Angular 4 Application

We can add Assets, Participants and can invoke a Transaction all from this Angular 4 application,

Adding an Asset AI123 From Bengaluru due to arrive in Delhi.

Updated by emp01

With Functional Working State

Adding a Employee with EmployeeID emp01

I have also added another employee with EmployeeID of emp02

Invoking a Transaction and Committing it to the ledger

Invoking Transaction

After the Commit we have Flight No: AI456, Location: Delhi, Working State: Non Functional and UpdatedBy: emp02

Committed Transaction

For any Queries and Doubts leave a comment if you liked the blog clap clap and clap!

Coinmonks

Coinmonks

Coinmonks is a non-profit Crypto educational publication.

Rietesh Amminabhavi

Written by

Network security | Blockchain developer | Student @ IITG https://rietesh.github.io

Coinmonks

Coinmonks

Coinmonks is a non-profit Crypto educational publication. Follow us on Twitter @coinmonks Our other project — https://coincodecap.com

More From Medium

More from Coinmonks

More from Coinmonks

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade