Extending the Hyperledger Fabric network Adding a new Peer
The Linux Foundation hosts Hyperledger, an enterprise-grade, permissioned blockchain network designed for distributed ledger solutions. The project advances cross-industry collaboration by developing robust distributed ledgers. It focuses primarily on performance and reliability so these systems can handle global business transactions for major technology, finance, and supply chain enterprises.
Hyperledger Fabric provides thorough documentation and tutorials. As more developers build on Fabric, questions naturally arise regarding advanced configurations—specifically, how to extend an existing network by adding new organizations or peers.
In this tutorial, we will extend an active Hyperledger Fabric network by adding a new peer.
Prerequisites & Environment Setup
First, complete the Build Your First Network (BYFN) tutorial from the official Hyperledger documentation. This step installs the required dependencies and environment components.
Next, clone the fabric-samples repository to your local machine:
git clone https://github.com/hyperledger/fabric-samples.git Navigate to the repository and download the latest Fabric platform-specific binaries and Docker images using the bootstrap script:
curl -sS https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap.sh -o ./scripts/bootstrap.sh
chmod +x ./scripts/bootstrap.sh
./scripts/bootstrap.sh Navigate to the first-network subdirectory inside fabric-samples. Standard setups start the network using the byfn.sh script, but our scenario requires CouchDB state databases.
Launch the initial network with CouchDB enabled:
./byfn.sh up -s couchdb -t 10000000 -s couchdb: Enables the CouchDB database engine.-t 10000000: Sets the CLI timeout parameter.
Once execution completes, you will have an active network topology consisting of:
Two Organizations:
Org1andOrg2Four Peers: Two peers per organization (
peer0,peer1), each paired with a CouchDB instanceOne Ordering Service Node (Orderer)
Verify the active containers:
docker ps Generating Crypto Material for the New Peer
We use Fabric’s
cryptogentool to generate cryptographic keys and certificates for the new peer node.Need skilled IT professionals?
Open
crypto-config.yamlin your text editor.Locate the
Org2configuration block and update the peerTemplate: Countfrom2to3.Save the file and return to your terminal inside the
first-networkdirectory.
Run the
extendcommand:
../bin/cryptogen extend --config=./crypto-config.yaml Deploying the New Peer & CouchDB Container
To launch the new peer and its database, create a dedicated Docker Compose configuration file named docker-compose-new-peer.yaml inside first-network.
Define the container configuration for peer2 and its CouchDB instance within this file, ensuring you assign unique, unused port bindings.
Launch the new containers:
docker-compose -f docker-compose-new-peer.yaml up -d This compose configuration bridges directly into our existing network, allowing the new node to communicate with the existing peers and orderer. Verify the new containers:
docker ps Note: Although peer2 is now running, it does not store any ledger data yet because it has not joined the channel.
Joining the Peer to the Channel
A Hyperledger Fabric channel is a private communication subnet that isolates transactions among specific network members. To transact and sync the ledger, peer2 must explicitly join the channel.
Access the CLI container:
docker exec -it cli bash Set the environment variables inside the CLI container to target the new peer (peer2 in Org2):
export CHANNEL_NAME=mychannel
export CORE_PEER_LOCALMSPID="Org2MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
export CORE_PEER_ADDRESS=peer2.org2.example.com:7051 Join the channel using the genesis block:
peer channel join -b mychannel.block peer2 will join mychannel and begin synchronizing ledger state from the channel’s existing peers. You can now install, approve, and commit chaincode to your newly integrated node.