deploying-bna-file-in-hyper-ledger-fabric-using-composer.png

Deploying .bna File in Hyperledger Fabric Using Composer

BlockChain Expert 17/October/2018

    Hyperledger composer is an application development framework tool used for creating blockchain applications and smart contract that can finally get executed in the platforms such as  Hyperledger Fabric Blockchain. Composer mainly emphasis on delivering a business solution quickly using a business-centric terminology. Using business use case like assets, transactions, participants composer has to build certain API to invoke transaction that creates, update and delete assets and transfer between the participants that occur within the business networks. With the help of hyperledger composer, it becomes easy to integrate to blockchain with the current business process and system of records.

 

    Hyperledger composer mainly helps to work with the current Hyperledger infrastructure, by using some pluggable consensus protocols in the blockchain, which will confirm that the transaction is valid according to the protocol implemented by parties on the network.

 

    The composer uses a web browser based User Interface called Composer Playground. The playground is available in both online and offline version. In the online version, we can directly use the playground, there is no need for any installation. On the other hand, in offline we can use them as our local host network, where editing and testing of sample business networks are made easily possible.

 

Online UI available in https://composer-playground.mybluemix.net

 

Installing the development environment

Installing the components needed to RUN Fabric.

Please go through the blog for Installing  prerequisiteshttp://www.blockchainexpert.uk/blog/installing-hyperledger-composer-playground

Or you can use the below steps for  Installing the components needed to RUN Fabric.

   

Step 1:

Firstly we need to install CLI tools. The most important tool we need is the composer-cli which is useful in a development environment.

Note that don't use sudo or su command use the below command as normal user.

 

npm install -g composer-cli@0.20

Here we are using version 0.20. You can download to the latest version available.

Install other npm node packages

 

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

 

Step 2:

Install the composer playground offline to run and test business network.

 

npm install -g composer-playground@0.20

Step 3:

In next step install hyperledger fabric. This installation will help you to create a local environment for the business network.

Run the below command by making a directory as fabric-dev-servers


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
unzip fabric-dev-servers.zip
./downloadFabric.sh

 

After downloading fabric now you can start fabric:

./startFabric.sh

deploying-bna-file-in-hyper-ledger-fabric-using-composer-1-blockchain-expert

Starting Hyperledger Fabric


For stopping fabric:

~/fabric-dev-servers/stopFabric.sh
Then create a peer admin card using the command
./createPeerAdminCard.sh

deploying-bna-file-in-hyper-ledger-fabric-using-composer-2-blockchain-expert

Open composer playground
Test your Blockchain application on composer playground. The Composer playground will help to create a .bna file

 http://www.blockchainexpert.uk/blog/installing-hyperledger-composer-playground

 Or you can manually create .bna file and can import

   

How to deploy a .bna file in Hyperledger Fabric using Composer playground

Here taking a sample bna file from composer playground animal tracking-network.

Install the PeerAdmin card to .bna file that you have created by using the command:

 

composer network install --card PeerAdmin@hlfv1 -a animaltracking-network.bna

deploying-bna-file-in-hyper-ledger-fabric-using-composer-3-blockchain-expert


composer network start

composer network start -c PeerAdmin@hlfv1 -n animaltracking-network -V 0.2.6-deploy.2 -A admin -S admin


deploying-bna-file-in-hyper-ledger-fabric-using-composer-4-blockchain-expert

Composer card import

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


deploying-bna-file-in-hyper-ledger-fabric-using-composer-5-blockchain-expert

Interfacing with blockchain using composer:

Hyperledger composer uses a Node.js that can expose a business network as a REST API. To develop web-based application REST API is used.

To launch the REST Server simply type:

$ composer-rest-server

? Enter the name of the business network card to use: admin@animaltracking-network
? Specify if you want namespaces in the generated REST API: always use namespaces
? Specify if you want to enable authentication for the REST API using Passport: No
? Specify if you want to enable event publication over WebSockets: Yes
? Specify if you want to enable TLS security for the REST API: No

To restart the REST server using the same options, issue the following command:
composer-rest-server -c admin@digitalproperty-network -n always -w

To restart the REST server using the same options, issue the following command:
composer-rest-server -c admin@digitalproperty-network -n always -wtrue
Discovering types from business network definition ...
Discovered types from business network definition
Generating schemasfor all types in business network definition ...
Generated schemas
Generated schemasfor all types in business network definition
Adding schemas
Adding schemasfor all types to Loopback ...
Added schemas
Added schemasfor all types to Loopback
Web server listening at: http://localhost:3002
Browse your REST API at http://localhost:3002/explorer
Web server listening at: http://localhost:3002
Browse your REST API at http://localhost:3002/explorer


deploying-bna-file-in-hyper-ledger-fabric-using-composer-6-blockchain-expert