Hyperledger Composer

This tutorial is inspired by the two tutorials linked at the end of this page.

Prerequisites
Tools: npm install -g composer-cli npm install -g composer-rest-server npm install -g generator-hyperledger-composer npm install -g yo

Hyperledger Fabric: mkdir ~/fabric-tools && cd ~/fabric-tools curl -O https://raw.githubusercontent.com/hyperledger/composer-tools/master/packages/fabric-dev-servers/fabric-dev-servers.zip unzip fabric-dev-servers.zip

cd ~/fabric-tools ./downloadFabric.sh

Launch some Fabric dockers cd ~/fabric-tools ./startFabric.sh

Generate a business network structure
yo hyperledger-composer:businessnetwork


 * Enter  for the network name, and desired information for description, author name, and author email.
 * Select  as the license.
 * Select  as the namespace.

Defining a business network
A business network is made up of assets, participants, transactions, access control rules, and optionally events and queries. In the skeleton business network created in the previous steps, there is a model file which will contain the class definitions for all assets, participants, and transactions in the business network. The skeleton business network also contains an access control document with basic access control rules, a script (logic.js) file containing transaction processor functions, and a package.json file containing business network metadata.

The first document to update is the model (.cto) file. This file is written using the Hyperledger Composer Modelling Language. The model file contains the definitions of each class of asset, transaction, participant, and event. It implicitly extends the Hyperledger Composer System Model described in the modelling language documentation.

Open the org.acme.biznet.cto model file to edit it.

The transaction processor function file contains the JavaScript logic to execute the transactions defined in the model file.

Open the logic.js script file to edit

Adding access control (optionnal)

/** * Access control rules for tutorial-network */ rule Default { description: "Allow all participants access to all resources" participant: "ANY" operation: ALL resource: "org.acme.biznet.*" action: ALLOW }
 * Create a  file in the tutorial-network directory.
 * Add the following access control rules to :

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

Generate a business network archive
Now that the business network has been defined, it must be packaged into a deployable business network archive (.bna) file. From the tutorial-network directory, run the following command:

composer archive create -t dir -n.

Deploying the business network
composer runtime install --card PeerAdmin@hlfv1 --businessNetworkName tutorial-network composer network start --card PeerAdmin@hlfv1 --networkAdmin admin --networkAdminEnrollSecret adminpw --archiveFile tutorial-network@0.0.1.bna --file networkadmin.card composer card import --file networkadmin.card composer network ping --card admin@tutorial-network

Generating a REST server
composer-rest-server



Sources:
 * https://hyperledger.github.io/composer/latest/installing/development-tools.html
 * https://hyperledger.github.io/composer/latest/tutorials/developer-tutorial