Skip to content

This is an example on a simple hyperledger composer model description and setup for a hyperledger fabric blockchain

Notifications You must be signed in to change notification settings

haduart/hyperledger-fabric-composer-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Testing out Hyperledger Fabric 1.12 & Composer setup

Setup hyperledger-fabric on mac

$ curl -O https://raw.githubusercontent.com/hyperledger/composer-tools/master/packages/fabric-dev-servers/fabric-dev-servers.zip
$ unzip fabric-dev-servers.zip
$ export FABRIC_VERSION=hlfv12
$ ./downloadFabric.sh
$ ./startFabric.sh

Using this commands you will download and start Hyperledger Fabric 1.12. Inside the fabric tools, you can go to the subfolder where the docker-compose file is, in that way is easier to see and control the docker containers:

$ cd fabric-scripts/hlfv11/composer/
$ docker-compose logs -f
$ docker-compose ps
$ docker-compose stop
$ docker-compose start
$ docker-compose pause
$ docker-compose unpause

Analyzing Docker Containers

Peer Node

$ docker exec -it 2770c86d71cf /bin/bash
$ peer node status
$ peer channel list

Commands:

  • chaincode: Operate a chaincode: install, instantiate, invoke, package, query, signpackage, upgrade
  • channel: Operate a channel: create, fetch, join, list, update
  • logging: Log levels: getlevel, setlevel, revertlevels
  • node: Operate a peer node: start, status
  • version: Print fabric peer version

Orderer

$ docker exec -it 6f2164d39d96 /bin/bash
$ orderer version
$ orderer --help

Certification Authority (CA)

$ docker exec -it 1e694d90d83f /bin/bash
$ fabric-ca-server --help
$ fabric-ca-client --help

CouchDB Node

http://192.168.99.100:5984/ or http://localhost:5984/

Using the hyperledger-composer yo generator

$ npm install -g yo
$ npm install -g generator-hyperledger-composer
$ yo hyperledger-composer

It can generate Angular example apps, Business Networks, LoopBack (an open API) and the Model.

Installing Hyperledger Composer CLI

$ npm install -g composer-cli
$ composer network deploy -a ./airlinev8@0.0.1.bna -c PeerAdmin@hlfv1 -A admin -S adminpwd

Participant Roles

Participants roles are under /Users/haduart/.composer

$ composer card --help
$ composer card list
$ composer card export --file test.card --card PeerAdmin@hlfv1
$ composer card delete --card  PeerAdmin@hlfv1

To create a new card, for example for the Admin (it’s the first one that you should create) you have to use the createPeerAdminCard script.

$ cd /Users/haduart/fabric-tools/fabric-scripts/hlfv11
$ ./createPeerAdminCard.sh
$ ./createPeerAdminCard.sh -h 192.168.99.100

Cards used by tools & SDK are managed on the file system and basically, there’s the connection.json and the credentials folder.

Setting up Composer Playground locally

Development tools

$ xcode-select --install
$ npm install node-gyp
$ npm install -g composer-rest-server
$ npm install -g generator-hyperledger-composer
$ npm install -g composer-playground
$ composer-playground

Deploying a Network Application

First, we need to create a business network model

$ yo hyperledger-composer

We will create a dist folder and create our first distribution:

$ composer archive create --sourceType dir --sourceName . -a ./dist/test-bna.bna
$ composer network install -a dist/test-bna.bna -c PeerAdmin@hlfv1
$ composer network start --networkName test-bna --networkVersion 0.0.3 --networkAdmin admin --networkAdminEnrollSecret adminpw --card PeerAdmin@hlfv1 --file test.card

After starting the BN there will be a file created. In our case it’s named test.card.

Then we should import the new Network Administrator’s card:

$ composer card import -f test.card

After importing the network card we can check its availability with the ping command:

$ composer network ping -c admin@test-bna

And check everything that has been pushed as a network with the network list command:

$ composer network list -c admin@test-bna

Upgrade the network to a new version

We build and install a new version into the network:

$ npm install
$ composer network install -a dist/test-bna.bna -c PeerAdmin@hlfv1

Then we upgrade to the new version:

$ composer network upgrade -c PeerAdmin@hlfv1 -n test-bna -V 0.0.4
$ composer network ping -c admin@test-bna

Starting Composer Rest Server

With the Rest server you can do CRUD operations and invoke transactions.

$ composer-rest-server -c admin@test-bna -p 3000 --explorer

Starting the REST server with multiple user mode enabled

Enabling multiuser

$  composer-rest-server -c admin@test-bna -p 3000 --explorer -m true

Enabling HTTPS and TLS by using the sample certificate and private key pair

$ composer-rest-server -c admin@test-bna -p 3000 --explorer -m true -t
$ composer-rest-server -c admin@test-bna -p 3000 --explorer -m true -t -e /tmp/cert.pem -k /tmp/key.pem

Creating an Angular app against the composer rest server

$ yo hyperledger-composer:angular

$ cd angular-test/
$ npm install
$ npm test
$ npm start

Check these projects!