Hyperledger Fabric
Blockchain Technology
Distributed Systems
Network Setup
Cross-PC Configuration

Set up of Hyperledger fabric on 2 different PCs

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Hyperledger Fabric is a permissioned blockchain platform aimed at enterprises, facilitating robust development frameworks for building blockchain applications. This guide will detail the process of setting up Hyperledger Fabric on two different PCs, focusing on a small network structure that's ideal for development or prototyping purposes.

Prerequisites

Before starting the setup, ensure that both PCs meet the following requirements:

  • Operating System: Ubuntu Linux 16.04 or higher (recommended for ease of installation)
  • Docker and Docker Compose: Crucial for running the Hyperledger Fabric containers.
  • Node.js and npm: Required if using the Fabric SDK for chaincode deployment.
  • Git: To clone the necessary repositories.
  • cURL: For downloading necessary files.

Step 1: Environment Setup

  1. Install Docker and Docker Compose: Follow the official installation guides to install Docker and Docker Compose.
  2. Install Node.js and npm: You can install Node.js and npm via nvm (Node Version Manager) as it allows you to easily switch between node versions.
bash
   curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
   nvm install 12.18.3 # Install a compatible version
   nvm use 12.18.3
  1. Install Git and cURL:
bash
   sudo apt-get update
   sudo apt-get install -y git curl

Step 2: Download Fabric Samples, Binaries, and Docker Images Execute the following command to clone the Hyperledger Fabric samples repository and download binaries.

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

This script downloads all necessary Docker images and binaries for setting up a Fabric network.

Network Setup and Configuration

Step 3: Creating the Network on PC1 (Primary Node)

  1. Navigate into the Fabric samples directory:
bash
   cd fabric-samples/test-network
  1. Start the Network:
bash
   ./network.sh up createChannel -c mychannel
   ./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-go -ccl go

This script starts the network, creates a channel named mychannel and deploys a basic chaincode.

Step 4: Setting Up the Secondary Node (PC2)

  1. Navigate to the Fabric samples directory on PC2.
  2. Join PC2 to the Existing Network: Execute the network joining script specifying necessary details like the channel name.
bash
   ./network.sh joinChannel -c mychannel

Verifying the Setup

Step 5: Chaincode Invocation and Query

  1. On PC1, invoke the chaincode:
bash
   ./network.sh invoke -c mychannel -ccn basic -c '{"function":"InitLedger","Args":[]}'
  1. On PC2, query the chaincode:
bash
   ./network.sh query -c mychannel -ccn basic -c '{"function":"GetAllAssets","Args":[]}'

If PC2 is able to query the data successfully, it verifies that both nodes are interacting with the same blockchain ledger instance across the network.

Troubleshooting Common Issues

  • Firewall and Network Configuration: Ensure all required ports are open and accessible between the two PCs. Fabric commonly uses ports such as 7050 (Orderer), 7051, and 7052 (Peers).
  • Docker and Docker Compose Issues: Check Docker daemon logs and ensure all containers are up and running properly.

Summary Table

ComponentDescriptionNotes
DockerContainer platform utilized by Fabric nodes.Ensure correct installation version
Node.js and npmUsed for running JavaScript-based chaincode and SDK.Use compatible version with Fabric
Network SetupInvolves starting a network, creating a channel, and joining it.Proper scripts execution is crucial
ChaincodeSmart contracts running on the network.Ensure proper deployment and testing

Conclusion

Setting up Hyperledger Fabric on multiple PCs involves careful synchronization and understanding of blockchain network fundamentals. With the primary node hosting the network and secondary nodes joining it, you can effectively simulate a distributed enterprise environment. This setup is instrumental for development, testing, and scaling of blockchain applications in a controlled environment.


Course illustration
Course illustration

All Rights Reserved.