Sitemap

Run Composer Playground on your Local Machine.

5 min readOct 30, 2018

--

In my previous blog ( Click Here) I wrote about ‘Deploy Hyperledger Fabric on IBM Cloud’. In this, We will discuss more of Hyperledger Composer. Writing code on online IDE is very easy and manageable. Hyperledger provides so many frameworks to work with but Hyperledger composer is one of my favorite which provides online IDE know as ‘Composer Playground’ to test chaincode without any basic installation on your local machine but when you want to deploy that chaincode on Fabric network then you have to do the basic installation on your local machine to generate .bna file which is very hectic . In this, we will see how to do with this installation in a few minutes. Let’s start!!!!!!

Set up your local machine with the following prerequisites:

Operating Systems: Ubuntu Linux 14.04 / 16.04 LTS (both 64-bit), or Mac OS 10.12
Docker Engine: Version 17.03 or higher
Docker-Compose: Version 1.8 or higher
Node: 8.9 or higher (note version 9 is not supported)
NPM: v5.x
Git: 2.9.x or higher
Python: 2.7.x

A code editor of your choice, we recommend VSCode.

If you’re running on Ubuntu, you can download the prerequisites using the following commands. Remember, don’t use sudo or login as root user before running the following commands:

curl -O https://ibm-blockchain.github.io/develop//develop/prereqs-ubuntu.sh chmod u+x prereqs-ubuntu.sh

Next, run the script — as this briefly uses sudo during its execution, you will be prompted for your password.

./prereqs-ubuntu.sh

If you are using VSCode, Install the Hyperledger Composer Extension for VSCode.

Launch VSCode and then press the “Extensions” button on the vertical left toolbar.

Type composer into the search bar and then press the Install button next to the Hyperledger Composer extension. Once the install completes you need to press the Reload button to activate the extension. After done with prerequisites run the command line tools on your local system.

Install the command line tools:

The commands line tools include composer-cli, the main IBM Blockchain Platform: Develop command line module; generator-hyperledger-composer, composer-rest-server, and Yeoman, these modules are used to generate business networks, bespoke REST servers, and Angular applications.

Get Vinay Chaudhary’s stories in your inbox

Join Medium for free to get updates from this writer.

I am providing two command line version in this tutorial which will be further compatible with your Hyperledger Fabric version v1.1 and v1.2.1 if you want to deploy the resultant .bna file on your fabric Network later.

  • Install composer-cli by using the following commands:
Hyperledger Fabric v1.2.1: npm install -g composer-cli@0.20.x
Hyperledger Fabric v1.1: npm install -g composer-cli@0.19.x
  • Install composer-rest-server by using the following command:
Hyperledger Fabric v1.2.1 :npm install -g composer-rest-server@0.20.x
Hyperledger Fabric v1.1: npm install -g composer-rest-server@0.19.x

Use the composer-rest-server module to create a REST Server on your machine to expose your business networks as RESTful APIs.

  • Install generator-hyperledger-composer by using the following command:
Hyperledger Fabric v1.2.1: npm install -g generator-hyperledger-composer@0.20.x
Hyperledger Fabric v1.1: npm install -g generator-hyperledger-composer@0.19.x

Use generator-hyperledger-composer to generate skeleton business network structures, models, and an Angular application.

  • Yeoman is a tool for generating applications, which utilizes generator-hyperledger-composer:
npm install -g yo

Creating the business network structure

  • Create a new directory for your project and navigate to it on the command line.
Press enter or click to view image in full size
  • From your new directory, use Yeoman to create a skeleton business network. The following command requires a business network name, description, author name, author email address, license selection, and namespace:
yo hyperledger-composer:businessnetwork
  • Enter tutorial-network for the network name, and desired information for description, author name, and author email. Also, provide Select Apache-2.0 as the license, Select org.acme.biznet as the namespace and Select No when asked whether to generate an empty network or not.
Press enter or click to view image in full size
  • Open the org.acme.biznet.cto model file in an editor of your choice. It is located in the models' folder of the business network you created in the last step and Replace the contents with the following information.
namespace org.acme.biznet
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
}
  • Save your changes to the org.acme.biznet.cto file.
  • Open the logic.js script file in the lib directory and Replace the contents with the following information:
function tradeCommodity(trade) {
trade.commodity.owner = trade.newOwner;
return getAssetRegistry('org.acme.biznet.Commodity')
.then(function (assetRegistry) {
return assetRegistry.update(trade.commodity);
});
}
  • Save your changes to logic.js
  • Create a permissions.acl file in the tutorial-network directory and Add the following access control rules to permissions.acl:
rule Default {
description: "Allow all participants access to all resources"
participant: "ANY"
operation: ALL
resource: "org.acme.biznet.*"
action: ALLOW
}

rule SystemACL {
description: "System ACL to permit all access"
participant: "ANY"
operation: ALL
resource: "org.hyperledger.composer.system.**"
action: ALLOW
}
  • Save your changes to permissions.acl
  • Using the command line, navigate to the tutorial-network directory. Also, From the tutorial-network directory, run the following command:
composer archive create -t dir -n
Press enter or click to view image in full size
  • After you run the command, a business network archive file (tutorial-network@0.0.1.bna) is created in the tutorial-network directory.
Press enter or click to view image in full size

Huhhhh!!! We have done with our tutorial ‘how to create .bna file locally. In the upcoming series, we will see how to deploy that .bna file on top of hyperledger fabric network using IBM Bluemix.

What to read next?

  1. Deploy .BNA on IBM Blumix.

--

--

Vinay Chaudhary
Vinay Chaudhary

Written by Vinay Chaudhary

Microservices | Kubernetes | Docker | Rest APIs | OAS 3.0 | Multiplatform Developer | Problem Solver ... https://www.linkedin.com/in/vinay-chaudhary-25369b36/