Unit III
Unit III
– IOE411
https://hyperledger-fabric.readthedocs.io/en/release-1.4/functionalities.html
Hyperledger Fabric – Design Features
• Assets
• Asset definitions enable the exchange of almost anything with
monetary value over the network -- from whole foods to
antique cars to currency futures.
• Assets can be represented in binary and/or JSON form.
• Chaincode
• Chaincode is a software that defines an asset or assets
• It is a business logic
• Chaincode enforces the rules for reading or altering key-value
pairs or other state database information.
• A system chaincode is a system-level chaincode that defines
the operating parameters for the entire channel.
https://hyperledger-fabric.readthedocs.io/en/release-1.4/fabric_model.html
Hyperledger Fabric – Design Features
• Ledger Features
• The ledger is the sequenced, tamper-resistant record of all
state transitions in the fabric.
• State transitions are a result of chaincode invocations
(‘transactions’) submitted by participating parties.
• Each transaction results in a set of asset key-value pairs that
are committed to the ledger as “creates, updates, or deletes”.
• Privacy
• Hyperledger Fabric employs an immutable ledger on a per-
channel basis.
• A ledger exists in the scope of a channel
– it can be shared across the entire network (assuming every
participant is operating on one common channel)
– OR, it can be privatized to include only a specific set of
participants.
Hyperledger Fabric
• Security & Membership Services
• Hyperledger Fabric provides a transactional network where all
participants have known identities.
• Permissioned membership provides a trusted blockchain
network, where participants know that all transactions can be
detected and traced by authorized regulators and auditors.
• How? Public Key Infrastructure is used to generate
cryptographic certificates which are tied to organizations,
network components, and end users or client applications
(using MSPs).
Hyperledger Fabric
• Consensus
• Consensus is defined as the full-circle verification of the
correctness of a set of transactions comprising a block.
• A unique approach to consensus enables the flexibility and
scalability needed for the enterprise.
• Consensus plays a major role throughout the process
– i.e., it plays a fundamental role in the entire transaction flow, from
proposal and endorsement, to ordering, validation and
commitment.
https://www.youtube.com/watch?v=1ORrdusUzeg
Blockchain Fabric Architecture
• The blockchain runs programs called chaincode, holds
state and ledger data, and executes transactions.
• Assumptions:
• a channel is set up and running.
• The application user has registered
and enrolled with the organization’s
Certificate Authority (CA) and received
back necessary cryptographic material,
which is used to authenticate to the
network.
https://hyperledger-fabric.readthedocs.io/en/release-1.4/txflow.html
Transaction Flow
• A Client, such as an iOS app, sends an API request to a Backend server
with Hyperledger Fabric SDK — I want to write some data to the
Blockchain
• The SDK sends a Transaction Request to the Peer(s) for the
endorsement
• The Peer(s) endorses (signs) the Transaction Request and returns it to
the SDK (, also, the Peer performs Chaincode / Smart Contract
execution at this point, before endorsing the transaction proposal)
• The SDK sends a transaction to the Orderer (& Kafka) for the
transaction ordering service
• The Orderer orders the transactions, forms block and broadcasts it to the
Peers
• The Peer(s) notifies the SDK — the block is committed in the Blockchain
for your data (, also, the Peer performs transactions validation and block
commitment at this point, before notifying the SDK)
• The SDK (the Backend server) sends an API response to a client — the
block is committed in the Blockchain for your data
https://hyperledger-fabric.readthedocs.io/en/release-1.4/txflow.html
Getting Started -- Fabric
• Download SDKs (go, Nodejs, Java, Python)
• The Hyperledger Fabric client SDK provides a structured
environment of libraries for developers to write and test
chaincode applications.
• The SDK is fully configurable and extensible through a
standard interface. Components, including cryptographic
algorithms for signatures, logging frameworks and state
stores, are easily swapped in and out of the SDK.
• Prerequisites
• Docker and Docker compose
• Golang
• Samples and binaries are available. Download them.
https://hyperledger-fabric.readthedocs.io/en/latest/glossary.html
https://hyperledger-fabric.readthedocs.io/en/latest/getting_started.html
Smart Contracts -- Chaincode
• A smart contract defines the rules between different
organizations in executable code.
• Applications invoke a smart contract to generate
transactions that are recorded on the ledger.
• Chaincode is a piece of code that implements the
smart contracts for businesses.
• i.e., chaincode contains smart contracts.
• Chaincodes are written in go or java or nodejs which
holds the business logic.
• It is installed and instantiated through an SDK or CLI
onto a network of Hyperledger Fabric peer nodes,
enabling interaction with that network’s shared ledger.
• Multiple smartcontracts can be implemented in on
chaincode.
Smart contracts -- Chaincode
• Examples
Chaincode Interfaces
• Init() method
• Init is called when you first deploy your chaincode.
• As the name implies, this function is used to do any
initialization for chaincodes.
• Invoke() method
• Invoke is called when you want to call chaincode functions to
do real work (i.e. read and write to the ledger).
• These two interfaces are also named as stub
interfaces
Chaincode program structure (golang)
• Step 1:
• Package main
• Step 2:
• Import packages
• Step 3:
• Define chaincode
Chaincode program structure (golang)
• Step 4:
• Implement chaincode interface
• Program Flow
• Generates certificates using cryptogen
• Generates genesis block (Orderer)
• Generates channel configuration → channel.tx
Hyperledger Fabric (Implementation)
Hyperledger Fabric (Implementation)
Hyperledger Fabric (Implementation)
Hyperledger Fabric (Implementation)
Hyperledger Fabric (Implementation)
• Identity
• Membership
• Peers
• Smart Contracts and Chaincode
• Ledger
• Ordering Service
• Private Data
• Channel Capabilities
• Use-Cases
Other frameworks under HyperLedger
Fabric
Iroha
Sawtooth
Burrow
Indy
Major Blockchains
• Bitcoin (Studied earlier)
• Bitcoins are virtual currencies
• Also called as cryptocurrency.
• Technologies such as public key, digital signature, hash, P2P,
Proof-of-Work
• Ethereum (Studied earlier)
• Ethereum is an open source distributed public blockchain
network; Ethereum is public;
• It is named as an internet built on neutral, open-access
infrastructure, controlled by no company or person.
• It includes smart contracts – written in solidity (high level
programming language).
• Solidity is statically typed scripting language which does the
process of verifying and enforcing the constraints at compile-
time as opposed to run-time.
• Ethereum has its native cryptocurrency called Ether &
Ethereum Wallet
Major Blockchains
• Ripple Consensus Network
• Ripple platform has been designed on open-source distributed
consensus ledger, and local currency referred as XRP.
• It is developed for digital asset exchanges, banks, payment
providers, and corporate who want to send money globally...
• Ripple allows quick, safe, secure and free financial
transactions around the globe without charge back.
• More towards global financial market.
• It is mainly meant for international wire transfers in a secure
manner.
• Hyperledger
• Studied earlier
https://www.ripple.com/
Major Blockchains
• R3’s Corda
• It is a distributed ledger using open source protocol which is
used to supervise, record, and sync the financial agreements
with the controlled financial institutions.
• Permissioned or private blockchain platform.
• Corda eliminates the unnecessary global sharing of data.
• In Corda, consensus is accomplished at individual deals and
not at the system level.
• It directly allows regulatory and supervisory observer nodes.
• Hence, they are legally bounded to financial sectors.
• It doesn’t have cryptocurrency.