Back to How-To Guides
HOW-TO12 min read2025-06-23

How to Set Up Hyperledger Fabric — Step-by-Step Network Deployment

A complete step-by-step guide to setting up a Hyperledger Fabric network — from prerequisites through crypto generation, channel creation, and chaincode deployment.

ClickMasters Team
Step-by-step implementation
Expert Assistance

Need Help Setting Up Hyperledger Fabric?

Get expert guidance on deploying and managing your Hyperledger Fabric network.

Complete Guide

Quick Answer

Setting up Hyperledger Fabric requires: prerequisites (Docker, Docker Compose, Fabric binaries), defining network structure, generating crypto material, creating channel artifacts, starting the network, creating and joining channels, and deploying chaincode. The most common deployment mistake is not testing certificate expiry rotation before going to production — certificates expire after 1 year and rotation requires careful coordination.

Prerequisites

Example
# Install Docker (required for Fabric containers)
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

# Install Docker Compose
sudo curl -L "https://github.com/docker/compose/releases/download/v2.20.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

# Install Fabric binaries
curl -sSL https://bit.ly/2ysbOFE | bash -s -- 2.5.0 1.5.7
export PATH=$PATH:$(pwd)/fabric-samples/bin

Step 1: Define Your Network Structure

Before running any commands, document your network:

How many organizations?

What is each org's MSP ID?

Which org runs the ordering service?

What channels will exist?

What chaincode will run on each channel?

Step 2: Generate Crypto Material

Example
# cryptogen: generates TLS certs and signing keys for all network components
cat > crypto-config.yaml << 'EOF'
OrdererOrgs:
  - Name: Orderer
    Domain: example.com
    Specs:
      - Hostname: orderer
    
PeerOrgs:
  - Name: Org1
    Domain: org1.example.com
    EnableNodeOUs: true
    Template:
      Count: 2       # 2 peer nodes for Org1
    Users:
      Count: 1       # 1 additional user besides admin

  - Name: Org2  
    Domain: org2.example.com
    EnableNodeOUs: true
    Template:
      Count: 2
    Users:
      Count: 1
EOF

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

Step 3: Create Channel Artifacts

Example
# configtx.yaml: defines organizations, policies, and genesis block
# Create channel transaction
configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/mychannel.tx -channelID mychannel

# Create genesis block for the ordering service
configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block

Step 4: Start the Network

Example
# docker-compose.yaml defines all network containers
docker-compose -f docker/docker-compose-test-net.yaml up -d

# Check all containers are running
docker ps

# Expected: peer0.org1.example.com, peer0.org2.example.com, orderer.example.com

Step 5: Create and Join Channel

Example
# Create channel (only once)
peer channel create -o orderer.example.com:7050   -c mychannel   -f ./channel-artifacts/mychannel.tx   --tls --cafile $ORDERER_CA

# Join Org1 peer to channel
peer channel join -b mychannel.block

# Switch to Org2 and join
export CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
export CORE_PEER_ADDRESS=peer0.org2.example.com:9051
peer channel join -b mychannel.block

Step 6: Deploy Chaincode

Example
# Fabric 2.x lifecycle: package → install → approve → commit

# Package
peer lifecycle chaincode package mycc.tar.gz   --path ./chaincode/mycc   --lang golang   --label mycc_1.0

# Install on each org's peers
peer lifecycle chaincode install mycc.tar.gz

# Approve for Org1
peer lifecycle chaincode approveformyorg   -o orderer.example.com:7050   --channelID mychannel   --name mycc   --version 1.0   --sequence 1   --tls --cafile $ORDERER_CA

# Approve for Org2 (same command, different env vars)
peer lifecycle chaincode approveformyorg ...

# Commit chaincode (after all required orgs have approved)
peer lifecycle chaincode commit   -o orderer.example.com:7050   --channelID mychannel   --name mycc   --version 1.0   --sequence 1   --tls --cafile $ORDERER_CA   --peerAddresses peer0.org1.example.com:7051   --peerAddresses peer0.org2.example.com:9051

Step 7: Test With Invoke and Query

Example
# Invoke chaincode function (state-changing)
peer chaincode invoke   -o orderer.example.com:7050   --channelID mychannel   --name mycc   -c '{"function":"createAsset","Args":["asset1","blue","5","Tomoko","300"]}'   --tls --cafile $ORDERER_CA

# Query chaincode (read-only)
peer chaincode query   -C mychannel   -n mycc   -c '{"Args":["ReadAsset","asset1"]}'

Frequently Asked Questions

Common questions before following this guide

Clear answers to the most common practical, technical, and implementation questions.

1

Answers

What is the most common Fabric deployment mistake?

Not testing certificate expiry rotation before going to production. Fabric certificates expire (default: 1 year for enrollment certs). Certificate rotation in production requires careful coordination across all peers and orderers. Test your certificate rotation procedure in staging before your first production cert expires.

Expert Assistance

Need Help Setting Up Hyperledger Fabric?

Get expert guidance on deploying and managing your Hyperledger Fabric network.