This tutorial will walk you through building a Hyperledger Composer blockchain solution from scratch. In the space of a few hours you will be able to go from an idea for a disruptive blockchain innovation, to executing transactions against a real Hyperledger Fabric blockchain network and generating/running a sample Angular 2 application that interacts with a blockchain network.
This tutorial gives an overview of the techniques and resources available to apply to your own use case.
Note: This tutorial was written against the latest Hyperledger Composer build on Ubuntu Linux running with Hyperledger Fabric v1.0 where referenced below and also tested for a Mac environment.
2. BlockChain Technology
Blockchain is a Decentralized, Distributed and immutable ledger
(group of transactions).
A block is the ‘current’ part of a blockchain, which records some
or all of the recent transactions. Once completed, a block goes
into the blockchain as a permanent database. Each time a block
gets completed, a new one is generated. There is a countless
number of such blocks in the blockchain, connected to each other
(like links in a chain) in proper linear, chronological order. Every
block contains a hash of the previous block
Each node (a computer connected to the network) gets a copy of
the blockchain, which is updated automatically.
3. Why Blockchain Technology?
Made Transactions transparent and secure because of
using cryptography patterns
No need of third Party to record transactions due to
decentralized nature of the technology.
Transferred power to people
High security to the data
Transactions cannot be altered or deleted because it is
an immutable ledger.
4. Types Of BlockChain
Public BlockChain :-
A public blockchain network is completely open and anyone can join and
participate in the network.
Drawbacks of a public blockchain is the substantial amount of computational
power that is necessary to maintain a distributed ledger at a large scale.
Implies little to no privacy for transactions
Example:- Bitcoin
Private BlockChain :-
Private Blockchain is Decentralized, distributed ledger and a permissioned
network.
A private blockchain network requires an invitation and must be validated by
either the network starter or by a set of rules
Admin can give permission to people who are in network to approve new people
Example:- HyperLedger Fabric
5. Smart Contract :- computer protocol intended to facilate, verify or enforce the
negotiation or performance of contract
Mining :- Adding transactions to the ledger
Peers :- Each node (a computer connected to the network) is called peer
Endorser :-Peer will simulate the transaction and ensure that the outcome is both
deterministic and stable
Committer :-The peer will validate the integrity of a transaction and then append to
the ledger.
Endorsement policy:- Instruct a peer on how to decide whether a transaction is
properly endorsed
Transactions:- Transactions are submitted by a participant to affect the assets held in
the asset registries on the Hyperledger blockchain
Consensus:- An agreement made between peers or organizations
Quick Notes
6. What is Hyperledger
Hyperledger is an umbrella project of open source blockchains and
related tools started in December 2015 by the Linux Foundation to
support the collaborative development of blockchain-
based distributed ledgers.
The “umbrella strategy” of Hyperledger incubates and promotes a
range of business blockchain technologies, framework, libraries,
interfaces, and application. Currently, Hyperledger is the host of the
following projects with frameworks.
Hyperledger Fabric
Hyperledger Sawtooth
Hyperledger Iroha
Hyperledger Indy
Hyperledger Burrow
7.
8. HyperLedger Fabric
Hyperledger Fabric is a blockchain framework implementation and one of the
Hyperledger projects hosted by The Linux Foundation.
Fabric is distinguished as a platform for permissioned networks, where all
participants have known identities.
It is built on a modular architecture that separates transaction processing into three
phases: distributed logic processing and agreement ("chaincode"), transaction
ordering, and transaction validation and commitment.
Latest release of Hyperledger fabric is v1.0
9. Prerequisites:
Docker - version 17.03.0-ce or greater
Docker Compose - version 1.8 or greater
Node.js - version 6.9.x or greater
NPM – version 3.10.10.
Go – 1.7x / JDK.
Hyperledger Fabric platform-specific binaries.
• Cryptogen.
• configtxgen,
• configtxlator,
• peer
Download the Docker images required for Fabric.
11. Chaincode
Chaincode, also called the smart contract, is essentially the business
logic that governs how the different entities or parties in a
blockchain network interact or transact with each other. Invocations
of the chaincode result in sets and gets of the ledger or world state
It is a piece of code that is deployed into a network of Hyperledger
fabric peer nodes that enables interaction with that network's shared
ledger.
Chaincode runs in a secured Docker container isolated from the
endorsing peer process. Chaincode initializes and manages ledger
state through transactions submitted by applications.
13. Chaincode Development
To start a development environment, we need to perform the following seven
tasks:
1. Build peer, orderer, and configtxgen executable binary .
2. Create genesis block for the orderer.
3. Start the orderer.
4. Start the peer.
5. Create channel configuration transaction and create a channel on orderer.
6. Join the peer to created channel.
7. Compile the chaincode and start executing.
8. Install and Instantiate the chaincode on the peer.
14. Working with chaincode :
Download Docker images : fabric-tools , fabric-orderer, peer , fabric-ccenv
Start the Network with docker-compose by creating a yaml file in terminal 1
which starts the orderer, peer .
On terminal 2 Build and start the chaincode from chaincode interpreter
command line using go build .
In other terminal 3 use the chaincode like install , instantiate , invoke and
query from the cli (command line interface)
When we invoke chaincode in terminal 3 Transactions will be seen on the
terminal 2
We can install more chaincodes in terminal 3 cli and verify in terminal 3.
15. Hyperledger Tools
Set of collaboration tools for building blockchain networks that make it simple
and quick for development.
Hyperledger Composer
Composer is a tool for building blockchain business networks, It used to create
smart contracts and blockchain applications to solve business problems.
Hyperledger Explorer
Explorer is a tool which provides a dashboard viewing information about
transactions ,blocks and smart contracts available on the network.
Hyperledger Cello
Cello can build up a Blockchain as a Service (BaaS) platform quickly from the
scratch. It reduce the effort required for creating, managing and terminating
blockchains.
16. HyperLedger Composer
Composer is a framework to accelerate the development of applications built on the
top of Blockchain platform such as Hyperledger Fabric
Start from the business level :model network assets, participants & transactions
Build Applications that use API's to invoke transactions, that create, update &delete
Assets are transfer between participants
Assets, participants ,transactions are recorded on Blockchain registries
Can easily integrate blockchain with existing business processes & system records
Modelling language: The Hyperledger Composer modelling language is used in the
business network definition to describe the assets, participants, and transactions in
the business network
17. 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
composer-cli
Yeoman generator
composer-rest-server
19. Composer PlayGround
The Hyperledger Composer Playground provides a user interface for the configuration,
deployment and testing of a business network
Without development environment setup we can still develop business network by
playground
In playground we can create or import network.bna file to generate or develop
business network
Playground mainly deals with assets, participants and transactions
If we do anything in the business network that will be save in transaction history which
cannot be change
Define tab:- Define tab we can define and work with model for your business network
Test tab:-can create assets and participants that were defined in the Define tab, and
test the functionality of your business network..
20. Developing Business network in playground
Click Deploy a new business network and give
Click empty-business-network then Deploy the Business network
To connect to our business network click Connect now under our business
network card.
Then add model file,script file and Access control file
Click Update to deploy the changes to our business network
Click the Test tab to test our Business network
The first thing we should add to our business network is to add participants
and assests.
Click the Submit Transaction button to submit our transactions
We can see all transactions in our business network by Click All Transactions
22. Deploying a business network to Hyperledger
Fabric for a single organization
Step-1 : Setup the development environment.
- https://hyperledger.github.io/composer/unstable/installing/development-tools.html
Step-2 : Build and start a Hyperledger Fabric network.
- http://hyperledger-fabric.readthedocs.io/en/release/build_network.html
Step-3 : Setup configuration tools cryptogen and configtxgen.
Step-4 : Create a connection profile use to connect with the Fabric network.
Step-5 : Locate the certificate and private key for the administrator.
23. Step-6 : Create a business network card that contains all of the information required to
connect to the business network. i.e, It includes Connection profile, Private key and
Certificate.
Step-7 : Import the business network card for the Hyperledger Fabric administrator.
Step-8 : Install Composer runtime onto all of the Hyperledger Fabric peer nodes,
this is nothing but a chaincode install operation. Here we specify the name of the
blockchain business network.
Step-9 : Start the blockchain business network, this is chaincode instantiate operation.
Step-10 : Import the business network card for the business network administrator.
Step-11 : Check that the business network has been deployed successfully.
Step-12: Generate a REST API based on the business network.
25. Deploying a Business network to Hyperledger
Fabric for multiple organizations
Multiple organization administrators configure their insatnces of Hyperledger
composer to interact with the same channel in Hyperledger fabric.
We can able to setup multiple organizations on single server or on multiple servers.
Here Organizations are nothing but participants involved in the bussiness network.
Each organization has its own peers to validate the transactions and orderer to confirm
transactions.
All the peers related to the organizations which are in the same channel are involved
in validating transactions.
27. Hyperledger Explorer
Docker image with an web-UI explorer for a running hyperledger chain
User friendly web application provides a dashboard for hyperledger to
view/query about blocks , transactions ,statistics and smartcontracts available on
network.
Users will be able to query for specific blocks or transactions and view the
complete details.
Future challenge is to integrate this explorer with other tools composer , cello for
displaying the information .
28. Installation Setup
Requirements:
Hyperledger Explorer works with Hyperledger Fabric 1.0. Install the following
software dependencies to manage fabric network.
Install and invoke the transactions through CLI(command line interpreter) which
will display transactions in the dashboard.
o Nodejs 6.9.x or greater
o Mysql 5.7 or greater
o Docker 17.06.2-ce or greater
o Docker-compose 1.14.0 or higher
Setup mysql database to save transactions , blocks and
chaincodes etc which are displayed in the dashboard.
Fabric Network Setup where we create a channel with peers
and orderers in a single network
Run the Blockchian Explorer which displayed the dashboard
in the localhost webpage.
31. Hyperledger Cello Overview
Hyperledger Cello can build up a Blockchain as a Service (BaaS) platform
quickly from the scratch.
Provides UI for add/delete hosts, create chain, view active chains, in
used chains.
System status will give status of host type, host status , chain type, chain status.
Cello should be deployed on multiple servers, at least 1 Master Node and 1
Worker Node.
It gives instance response even with hundreds of chains or nodes.
33. Master Node
Master node will run cello services(docker images) I.e.,
Nginx(is used as a reverse proxy to improve web performance).
Mongo( is used as the backend database).
Cello-dashboard( Provides the admin dashboard).
Cello-watchdog(Monitors the status of the system e.g., chains' health).
Cello-restserver(Core engine to do the provision, orchestration and
management).
It will manage the blockchain networks running inside the Worker nodes.
It will add/manage/delete worker nodes.
It can add chains for worker nodes.
34. Worker Node
The servers to have blockchains running inside.
worker nodes will be managed by the master node.
Docker daemon should be in running.
Blockchain network can be created with Hyperledger Fabric network,
a SawthoothLake or Iroha chain.
Now we are using Hyperledger Fabric.
36. Docker
Docker is a tool designed to make it easier to create,
deploy, and run applications by using containers.
Containers allow a developer to package up an
application with all of the parts it needs, such as
libraries and other dependencies, and ship it all out as
one package.
So that developers need not worry about system setup,
they can focus on writing code.
Docker is a bit like a virtual machine. But unlike a
virtual machine, rather than creating a whole virtual
operating system, Docker allows applications to use the
same Linux kernel as the system that they're running on
and only requires applications be shipped with things
not already running on the host computer.
37. Docker Swarm
Docker swarm will connect multiple
nodes.
A Manager node can add multiple
worker nodes.
When a manager node runs a container,
the replicas of that container will be
added in worker node.