decrypt101
SocialOpen ProjectsSupport me My Resumes
  • Preface
    • Motivation
    • Roadmap’s
  • Introduction to Blockchain
    • A Brief History
    • Growth of Blockchain
    • Structure of Blockchain
    • Types of Blockchain
    • Key Technologies of Blockchain
    • Features of Blockchain
    • How Blockchain Works ?
    • Implementation of Blockchain
    • Summary
  • Components of Blockchain Architecture
    • Distributed Ledger
    • Blocks
    • Transaction
    • Chain
    • Peer-to-Peer Network
    • Blockchain Layers
    • Off-Chain & On-Chain
    • Wallet
    • Mining
    • Tokens
    • Assets
    • State Channels
    • Sidechains
    • Oracles on Blockchain
    • Atomic Swaps
    • Decentralized Identity (DID)
    • Blockchain Data Storage
    • Interoperability
    • Data structures for Scaling Blockchain
    • Maximal Extractable Value (MEV)
  • Consensus Mechanisms
    • Proof of Work (PoW)
      • Implemation Using Rust
    • Proof of Stake (PoS)
    • Proof of Burn (PoB)
    • Proof of Capacity (PoC)
    • Proof of Activity (PoAc)
    • Proof of Weight (PoWe)
    • Proof of Luck (PoL)
    • Proof of Ownership (PoO)
    • Proof of Existence (PoE)
    • Proof of Believability (PoBe)
    • Proof of History (PoH)
    • Proof of Authority (PoA)
    • Proof of Elapsed Time (PoET)
  • Cryptographics
    • Encryption & Decryption
      • Symmetric Encryption
      • Asymmetric Encryption
      • Key Management and Exchange
      • Implementation
    • Cryptographic Hashing
      • Secure Hash Algorithms (SHA)
      • Message Digest Algorithms
      • Ethash
      • Blake2
      • SCrypt
      • RIPEMD-160
    • Digital Signature
      • Digital Signature Algorithms
      • Digital Signature in Blockchain
    • Zero-Knowledge Proofs (ZKPs)
      • Types of Zero-Knowledge Proof and Protocols
      • A Case Study of Polygon Platform
    • Multi-Party Computation (MPC)
    • Cryptanalysis
    • Practical Implementation
  • Decentralized Application (DApp)
    • Design and UX in Web3
  • Smart Contract
    • Development Tools
    • Solidity
    • Testing Smart Contract
    • Developing Smart Contract
    • Interacting & Deploying with Smart Contract
    • Verifying Smart Contracts
    • Upgrading Smart Contracts
    • Securing Smart Contract
    • Smart Contract Composability
    • Testnet and Mainnet
    • Blockchain Platform Using Smart Contract
    • Application of Smart Contract
    • Practical Implementation
  • Blockchain Platforms
    • Ethereum
      • Ethereum Virtual Machine (EVM)
      • ETHER and GAS
      • Ethereum transaction
      • Ethereum Accounts
      • Ethereum Stacking
      • Ethereum Network
      • Ethereum Scaling Solutions
      • Ethereum Use-Cases
      • Getting Started with Ethereum
      • Ethereum Ecosystem and Support
    • Solana
      • Solana Architecture
        • Solana Account Model
        • Solana Wallet
        • Transactions and Instructions
        • Solana Programs
        • Program Derived Address (PDA)
        • Cross Program Invocation (CPI)
        • Tokens on Solana
        • Clusters and Public RPC Endpoints
        • Transaction Confirmation & Expiration
        • Retrying Transactions
        • Versioned Transactions
        • Address Lookup Tables
        • State Compression
        • Actions and Blinks
      • Solana Developments
      • Solana Client
      • Advanced Solana
      • Solana Scaling and Performance Architecture
      • Solana Solutions and cases
      • Practical Implemenation
    • Binance Smart Chain (BSC)
      • Create a BEP20 Token
    • Hyperledger Fabric
    • Cosmos
    • Polkadot
    • Quorum
    • Polygon
    • Algorand
    • Corda
    • Avalanche
    • TRON
    • Summary
  • Decentralized Finance (DeFi)
    • DeFi Components
    • DeFi Protocols
    • DeFi Platforms
    • DeFi Risk Classification
      • Infrastructure-layer Attacks
      • Smart Contract Layer-attacks
      • Application Layer-attacks
      • DeFi Risks
    • DeFi and Blockchain
    • DeFi Impact
  • Decentralized Ecosystem and Digital Innovation
    • Layer 2 Scaling Fundamental
    • Tokenomics
    • Cryptocurrency
    • Quantative Trading
    • NFTs
    • GameFi
    • Metaverse
  • Blockchain as a Service (BaaS)
    • Building Fullstack Blockchain Platform
    • Decentralized Digital Identity
    • Build a Cryptocurrencies Exchange
    • Play-to-Earn Gaming
    • Solana Token Airdrop Manager
    • Smart Contract Development on Solana with Rust
    • Quantitative Trading Platform
    • Insurances protocols
    • Flash Loans
    • Asset Management
    • Tokenized Derivatives
    • Automated Market Makers (AMMs)
    • Staking
    • Lending and Borrowing Platforms
    • Yield Farming
    • Stablecoin System
    • Security Token Offerings (STOs)
    • Initial Coin Offerings (ICOs)
    • On-Chain Voting Systems
    • Decentralized Autonomous Organizations (DAOs)
    • NFT Marketplaces
    • Provenance Verification
    • Supply Chain Tracking
    • Commodities Tokenization
    • Real Estate Tokenization
    • Digital Certificates
    • KYC (Know Your Customer)
  • Blockchain Development Across Languages
    • Blockchain using Go(Golang)
    • Blockchain using Rust
    • Blockchain using Python
    • Blockchain using Cairo
  • Distributed Systems & Infrastructure Technology
    • Classification of Distributed Systems
    • Networked systems versus Distributed systems
    • Parallel systems vs Distributed systems
    • Distributed versus Decentralized systems
    • Processes of Distributed Systems
    • Architecture of Distributed systems
    • Infrastructure Technologies
  • Distributed System Patterns
    • Distributed Agreements Algorithms
      • HoneyBadgerBFT
    • Data Replications
    • Data Partition
    • Consistency
    • Distributed Time
    • Cluster Management
    • Communication between Nodes
    • Fault Tolerance and Resilience
      • How to design better fault tolerance systems
      • Resilience Patterns
    • Coordination systems
      • Clock synchronization
    • Security
      • Trust in distributed systems
      • Design of Principal Security
      • Security threats, policies, and mechanisms
      • Authentication and Authorizations
      • Cryptography
      • Monitoring in Security
  • Distributed System Design
    • Page 1
    • Distributed Shared Memory
    • Distributed Data Management
    • Distributed Knowledge Management
    • Distributed Ledger
  • FAQs
  • Support and Community
Powered by GitBook
On this page
  • What is Hyperledger Fabric?
  • Why Use Hyperledger Fabric?
  • Hyperledger Fabric Architecture Explained
  • Getting Started with Hyperledger Fabric
  • Setting Up A Hyperledger Fabric Network From Scratch Example with Golang
  • Example Usage of Hyperledger Fabric
  1. Blockchain Platforms

Hyperledger Fabric

What is Hyperledger Fabric?

Hyperledger Fabric is an open-source, permissioned blockchain framework designed for enterprise-level applications. Unlike public blockchains (e.g., Ethereum or Bitcoin), where anyone can participate, Hyperledger Fabric is permissioned, meaning participants are pre-approved and verified. It is part of the broader Hyperledger project, which is hosted by The Linux Foundation, aimed at advancing cross-industry blockchain technologies.

Key characteristics of Hyperledger Fabric:

  • Permissioned nature: Only trusted and authorized entities can join the network, providing privacy and better control.

  • Modular architecture: Fabric is highly modular, allowing for customization of components like consensus mechanisms, identity management, and membership services.

  • Pluggable consensus: Unlike traditional blockchains that rely on Proof of Work (PoW), Hyperledger Fabric supports pluggable consensus, meaning the consensus protocol can be chosen based on the use case.

  • Private channels: It enables private communication channels between a subset of network participants, ensuring confidentiality for sensitive transactions.

  • Smart contracts: Known as chaincode in Hyperledger Fabric, smart contracts define the logic governing transactions.

Why Use Hyperledger Fabric?

Hyperledger Fabric is designed to meet the needs of enterprises looking to implement blockchain technology for secure, private, and scalable solutions. Here’s why it stands out:

  1. Permissioned Network: Unlike public blockchains, where anyone can participate, Hyperledger Fabric uses a permissioned approach. This ensures that only authorized participants can join the network, making it ideal for industries that require trust and controlled access (e.g., banking, healthcare, and supply chains).

  2. Modularity and Flexibility: Fabric’s modular architecture allows organizations to customize components such as consensus protocols, identity management systems, and membership services. This enables businesses to tailor the blockchain network to their specific requirements and regulatory needs.

  3. Data Privacy and Confidentiality: Hyperledger Fabric allows for the creation of private channels, enabling confidential transactions between specific participants. This feature is critical in industries dealing with sensitive information, such as finance or healthcare, where privacy is a major concern.

  4. Pluggable Consensus: Organizations can choose the consensus mechanism that best suits their use case. For example, in a consortium of trusted parties, a simpler consensus mechanism can be chosen over energy-intensive mechanisms like Proof of Work (PoW).

  5. Efficient Transaction Processing: Fabric is designed for fast and efficient transaction processing, as it separates transaction endorsement from the actual ordering of transactions. This results in lower latency and better performance, even in complex networks.

  6. Enterprise-Level Security: Fabric includes robust identity management and access control systems, providing a high level of security. These systems ensure that only verified participants can access the network and execute transactions.

  7. Chaincode (Smart Contracts): Hyperledger Fabric uses chaincode (the equivalent of smart contracts) to define the business logic of transactions. Chaincode can be written in general-purpose programming languages like Go, Java, and Node.js, which makes it easier for enterprises to integrate blockchain with their existing systems.

  8. Scalability: Fabric’s architecture allows for scalability through its endorsement model, which minimizes the computational overhead associated with consensus across the entire network. This ensures that large, complex business networks can scale effectively.

  9. Industry Adoption and Support: Many industries, including banking, supply chain management, healthcare, and government, are adopting Hyperledger Fabric for its reliability, scalability, and enterprise support. It's backed by a large community of developers and contributors under The Linux Foundation, ensuring continued development and support.

In summary, Hyperledger Fabric is used for its secure, flexible, and scalable approach to blockchain, making it suitable for a wide range of enterprise applications where privacy, trust, and performance are critical.

Hyperledger Fabric Architecture Explained

Hyperledger Fabric’s architecture is built on a modular and highly flexible design that separates transaction processing into three distinct phases: endorsement, ordering, and validation. This separation enhances scalability and performance while maintaining security and data integrity.

  1. Participants and Roles:

    • Clients: Initiate transactions by sending proposals to peers.

    • Peers: Nodes that maintain the ledger and execute chaincode (smart contracts). They validate transactions and can endorse them.

    • Orderers (Ordering Service): Responsible for ordering transactions into a block. This service establishes consensus on the order of transactions.

    • Certificate Authority (CA): Manages identity and access through digital certificates, using the Public Key Infrastructure (PKI).

  2. Ledger:

    • Fabric has a distributed ledger that consists of two parts:

      • World State: The current state of the ledger (key-value pairs).

      • Blockchain: Immutable, append-only log of all transactions.

    • The world state can be stored in databases like LevelDB or CouchDB (for complex querying).

  3. Chaincode (Smart Contracts):

    • Business logic is executed using chaincode, Fabric's term for smart contracts. Chaincode is installed on peers and invoked by clients. Chaincode can be written in multiple languages (e.g., Go, Java, Node.js).

  4. Endorsement:

    • When a transaction proposal is sent by a client, it must be endorsed by specific peers (endorsing peers). These peers execute the chaincode but do not update the ledger yet. Instead, they generate an endorsement signature if the transaction is valid according to the business logic.

  5. Ordering Service:

    • The ordering service collects endorsed transactions and orders them into blocks. It doesn't validate the transactions but establishes consensus on their order. The ordering service can be implemented using protocols like Kafka, Raft, or Solo (development use only).

  6. Validation and Commitment:

    • Once the orderers have arranged transactions into blocks, these blocks are sent to all peers for validation. The peers check:

      • Endorsement Policy: If the required endorsements are present.

      • MVCC (Multi-Version Concurrency Control): Ensures there are no conflicts in the world state.

    • Valid transactions are then committed to the ledger, updating both the blockchain (historical log) and the world state (current snapshot).

  7. Channels:

    • Hyperledger Fabric allows the creation of channels, which are private sub-networks within the overall blockchain network. Only participants in a channel can access the data and transactions in that channel, providing fine-grained privacy and confidentiality.

  8. Membership Service Provider (MSP):

    • MSP is responsible for identity management. It ensures only authenticated participants can interact with the network. It works closely with the CA to issue certificates and manage access.

    Hyperledger Fabric’s architecture leverages modular components for flexibility, ensures high scalability through a separated transaction flow, and enables privacy with channels and permissioned access. The combination of roles like peers, orderers, and smart contracts (chaincode) ensures a secure and efficient blockchain suited for enterprise needs.

Getting Started with Hyperledger Fabric

To get started with Hyperledger Fabric, follow these key steps:

  1. Set Up Development Environment:

    • Install dependencies: Docker, Docker Compose, Node.js, and Go.

    • Install the Hyperledger Fabric CLI and binaries by downloading them from the official repository.

  2. Download Fabric Samples:

    • Clone the Fabric Samples repository from GitHub: git clone https://github.com/hyperledger/fabric-samples.git

    • This repo includes examples, configuration files, and the scripts to start a test network.

  3. Run a Test Network:

    • Navigate to the test network sample: cd fabric-samples/test-network

    • Use the provided script to bring up a basic network (2 organizations and 1 channel): ./network.sh up

    • To create a channel: ./network.sh createChannel

  4. Deploy Chaincode (Smart Contract):

    • Use the same script to deploy a basic chaincode: ./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-go -ccl go

    • This will install and instantiate the chaincode for managing assets.

  5. Interact with the Network:

    • You can now invoke transactions and query the ledger using the Fabric CLI or SDK (Node.js, Go).

    • Example query command to view assets: peer chaincode query -C mychannel -n basic -c '{"Args":["GetAllAssets"]}'

  6. Explore the Fabric Samples:

    • Fabric Samples include various use cases and tutorials, such as asset transfers, private data, and events.

Once you get the test network running and deploy your first chaincode, you can explore advanced configurations, custom chaincode development, or multi-organization setups.

Setting Up A Hyperledger Fabric Network From Scratch Example with Golang

Here’s a step-by-step guide to setting up a basic Hyperledger Fabric network and deploying chaincode written in Golang.

Prerequisites:

  • Docker and Docker Compose

  • Go (Golang)

  • Fabric Binaries (peer, orderer, configtxgen, cryptogen, etc.)

  • Fabric Samples (optional, for reference)


1. Install Dependencies

Ensure Docker, Docker Compose, and Go are installed on your system.

  • Install Docker:

    sudo apt install docker.io
    sudo systemctl enable docker
    sudo systemctl start docker
  • Install Go (if not installed):

    wget https://go.dev/dl/go1.20.6.linux-amd64.tar.gz
    sudo tar -C /usr/local -xzf go1.20.6.linux-amd64.tar.gz
    export PATH=$PATH:/usr/local/go/bin
  • Clone Hyperledger Fabric Samples and binaries:

    git clone https://github.com/hyperledger/fabric-samples.git
    cd fabric-samples
  • Install the Fabric binaries:

    curl -sSL https://bit.ly/2ysbOFE | bash -s

2. Set Up the Network Configuration

You’ll need to create certificates and configuration files for the network participants (organizations, peers, orderers).

  • Generate Certificates using cryptogen for two organizations:

    cryptogen generate --config=./crypto-config.yaml

    This creates the identities (keys and certificates) for the peers and orderers.

  • Generate Genesis Block for the ordering service:

    configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block
  • Create Channel Configuration Transaction:

    configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannel

3. Launch the Network with Docker Compose

  • Create a docker-compose.yaml file that defines the Docker containers for peers, orderers, and CouchDB. An example snippet:

    version: '2'
    
    services:
      orderer.example.com:
        image: hyperledger/fabric-orderer
        ...
    
      peer0.org1.example.com:
        image: hyperledger/fabric-peer
        ...
  • Start the network:

    docker-compose -f docker-compose.yaml up -d

4. Create the Channel and Join Peers

  • Create Channel:

    docker exec -it cli peer channel create -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/channel.tx
  • Join Peers to Channel:

    docker exec -it cli peer channel join -b mychannel.block

5. Write and Deploy Golang Chaincode

Create your Golang chaincode in the asset-transfer-basic folder. For example, a simple asset transfer smart contract:

package main

import (
	"encoding/json"
	"fmt"
	"github.com/hyperledger/fabric-contract-api-go/contractapi"
)

// Define the Asset structure
type Asset struct {
	ID             string `json:"id"`
	Owner          string `json:"owner"`
	Price          int    `json:"price"`
}

// AssetContract implements the chaincode interface
type AssetContract struct {
	contractapi.Contract
}

// CreateAsset adds a new asset
func (s *AssetContract) CreateAsset(ctx contractapi.TransactionContextInterface, id string, owner string, price int) error {
	asset := Asset{
		ID:    id,
		Owner: owner,
		Price: price,
	}
	assetJSON, err := json.Marshal(asset)
	if err != nil {
		return err
	}
	return ctx.GetStub().PutState(id, assetJSON)
}

// QueryAsset returns an asset by ID
func (s *AssetContract) QueryAsset(ctx contractapi.TransactionContextInterface, id string) (*Asset, error) {
	assetJSON, err := ctx.GetStub().GetState(id)
	if err != nil {
		return nil, err
	}
	if assetJSON == nil {
		return nil, fmt.Errorf("asset not found")
	}
	var asset Asset
	err = json.Unmarshal(assetJSON, &asset)
	if err != nil {
		return nil, err
	}
	return &asset, nil
}

func main() {
	chaincode, err := contractapi.NewChaincode(new(AssetContract))
	if err != nil {
		fmt.Printf("Error creating chaincode: %s", err)
	}
	if err := chaincode.Start(); err != nil {
		fmt.Printf("Error starting chaincode: %s", err)
	}
}
  • Package the Chaincode:

    peer lifecycle chaincode package basic.tar.gz --path ../asset-transfer-basic --lang golang --label basic_1.0
  • Install Chaincode on Peers:

    peer lifecycle chaincode install basic.tar.gz
  • Approve Chaincode for Organizations and commit the chaincode.


6. Interact with the Chaincode

  • Invoke Chaincode (e.g., creating an asset):

    peer chaincode invoke -o orderer.example.com:7050 -C mychannel -n basic -c '{"Args":["CreateAsset","asset1","Alice","100"]}'
  • Query Chaincode (e.g., retrieve the asset details):

    peer chaincode query -C mychannel -n basic -c '{"Args":["QueryAsset","asset1"]}'

You have now set up a basic Hyperledger Fabric network with a Golang chaincode! This can be expanded to multiple peers, orderers, and more complex chaincode logic.

Example Usage of Hyperledger Fabric

Hyperledger Fabric is commonly used across various industries due to its permissioned architecture, privacy features, and modular design. Here are a few example use cases:

1. Supply Chain Management

  • Problem: Traditional supply chains often suffer from lack of transparency, delays in communication, and fraud.

  • Solution: Hyperledger Fabric enables a blockchain network where each participant (suppliers, manufacturers, logistics companies, etc.) can track and share real-time information about goods and their status. The use of private channels ensures that sensitive data is only visible to authorized parties.

  • Example: Walmart uses Fabric to track the supply chain of food products from farm to shelf, ensuring better traceability, safety, and compliance.

2. Trade Finance

  • Problem: International trade finance involves many intermediaries, leading to delays and high costs.

  • Solution: Hyperledger Fabric facilitates real-time communication and trusted transactions between banks, exporters, and importers. Using Fabric’s smart contracts (chaincode), documents like letters of credit and bills of lading can be verified, transferred, and executed automatically on the blockchain.

  • Example: IBM’s We.Trade platform uses Hyperledger Fabric to streamline cross-border trade for small and medium-sized enterprises (SMEs).

3. Healthcare and Medical Records

  • Problem: The lack of interoperability between healthcare systems and concerns over patient privacy make it difficult to share medical records securely.

  • Solution: Hyperledger Fabric allows healthcare providers to share patient records over private channels, ensuring that only authorized participants (e.g., doctors, hospitals, and patients) can access sensitive data. This improves coordination and patient outcomes while preserving privacy.

  • Example: MediLedger uses Hyperledger Fabric for tracking pharmaceutical supply chains and verifying drug authenticity, addressing issues like counterfeit drugs.

4. Digital Identity Management

  • Problem: Managing identities across different platforms and verifying user credentials can be complex and prone to fraud.

  • Solution: Hyperledger Fabric provides a secure way to manage digital identities. Users can store and control their identities on the blockchain, granting access to trusted third parties only when needed. This ensures privacy and reduces the risk of identity theft.

  • Example: The Sovrin Network uses Hyperledger Indy (part of the Hyperledger project) for decentralized identity solutions, but Hyperledger Fabric can also be applied for enterprise-level identity verification.

5. Government and Public Records

  • Problem: Public records (e.g., land titles, birth certificates) are often fragmented, leading to inefficiencies, loss, and fraud.

  • Solution: Governments can use Hyperledger Fabric to digitize and securely store public records, making it easier to verify ownership or validate documents while ensuring only authorized users access sensitive data.

  • Example: DigiCerts, a blockchain-based land registry system, uses Fabric to digitize and streamline land records for governments in Africa.


Key Projects on Hyperledger Fabric

  1. IBM Food Trust IBM Food Trust is a blockchain-based solution built on Hyperledger Fabric that improves food traceability throughout the supply chain. The platform enables producers, suppliers, distributors, and retailers to share data in real-time, ensuring food safety and reducing waste. Major players like Walmart, Nestle, and Carrefour are using this system.

  2. We.Trade We.Trade is a blockchain-based trade finance platform that facilitates cross-border transactions between small and medium-sized businesses (SMEs) in Europe. It uses Hyperledger Fabric to streamline transactions, reduce the need for intermediaries, and offer services like invoice financing and payment guarantees.

  3. TradeLens Developed by IBM and Maersk, TradeLens is a global shipping and supply chain platform that uses Hyperledger Fabric to improve the efficiency and transparency of container shipping. The platform connects shipping companies, port operators, and customs authorities to streamline workflows and reduce paper-based processes.

  4. MediLedger MediLedger is a blockchain-based network for the pharmaceutical supply chain. It is designed to track drugs, prevent counterfeits, and ensure compliance with regulations. MediLedger uses Hyperledger Fabric’s permissioned architecture to maintain privacy while ensuring the integrity of pharmaceutical data.

  5. SecureKey Technologies SecureKey developed a blockchain-based digital identity verification system, Verified.Me, that allows consumers to share their identity and credentials with financial institutions and government agencies securely. Built on Hyperledger Fabric, it provides privacy-centric identity solutions for Canadian institutions.

  6. Honeywell GoDirect Trade Honeywell’s GoDirect Trade is an online marketplace for the sale of aerospace parts, powered by Hyperledger Fabric. The platform uses blockchain to provide transparency, track part authenticity, and enable secure digital transactions for buying and selling used or surplus parts.


PreviousCreate a BEP20 TokenNextCosmos

Last updated 7 months ago

Page cover image