Add a New Organization on Existing Hyperledger Fabric Network


Overall Process

Review: Build Your First Network

Process of Adding Org3 into First Network

0. Bring Up First Network with

$ cd fabric-samples/first-network
$ ./ up

1. Prepare Org3 artifacts


// in first-network/org3-artifacts directory
$ ../../bin/cryptogen generate --config=./org3-crypto.yaml
// in first-network/org3-artifacts directory
$ cp -r ../crypto-config/ordererOrganizations crypto-config/


// in first-network/org3-artifacts directory
$ export FABRIC_CFG_PATH=$PWD && ../../bin/configtxgen -printOrg Org3MSP > ../channel-artifacts/org3.json
org3.json, generated by configtxgen

2. Update the network to include Org3 configuration

The Idea

Tool: configtxlator

2.1 fetch the latest configuration block from the ledger

$ docker exec -it cli bash
# export ORDERER_CA=/opt/gopath/src/ && export CHANNEL_NAME=mychannel
# peer channel fetch config config_block.pb -o -c $CHANNEL_NAME --tls --cafile $ORDERER_CA
Block #2 is the latest configuration block after running ./ up script.

2.2 prepare the configuration update for Org3

# configtxlator proto_decode --input config_block.pb --type common.Block | jq[0] > config.json
Right-hand-side is the useful extraction from the block
# jq -s '.[0] * {"channel_group":{"groups":{"Application":{"groups": {"Org3MSP":.[1]}}}}}' config.json ./channel-artifacts/org3.json > modified_config.json
The three files: org3.json is inserted into config.json, resulting modified_config.json
# configtxlator proto_encode --input config.json --type common.Config --output config.pb# configtxlator proto_encode --input modified_config.json --type common.Config --output modified_config.pb# configtxlator compute_update --channel_id $CHANNEL_NAME --original config.pb --updated modified_config.pb --output org3_update.pb
# configtxlator proto_decode --input org3_update.pb --type common.ConfigUpdate | jq . > org3_update.json# echo '{"payload":{"header":{"channel_header":{"channel_id":"mychannel", "type":2}},"data":{"config_update":'$(cat org3_update.json)'}}}' | jq . > org3_update_in_envelope.json# configtxlator proto_encode --input org3_update_in_envelope.json --type common.Envelope --output org3_update_in_envelope.pb
The org3_updated.json is wrapped into org3_updated_in_envelope.json
From config_block.pb (latest configuration block) to the org3_update_in_envelope.pb

2.3 sends update to Orderer and a new block containing Org3 configuration is committed back to the ledger

// a new terminal for peer0.org2$ docker exec -e CORE_PEER_LOCALMSPID="Org2MSP" -e CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/ -e CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/ -e -it cli bash// perform export environment as well# export ORDERER_CA=/opt/gopath/src/ && export CHANNEL_NAME=mychannel
// cli for peer channel signconfigtx -f org3_update_in_envelope.pb
// cli for peer channel update -f org3_update_in_envelope.pb -c $CHANNEL_NAME -o --tls --cafile $ORDERER_CA
// cli for both peer0.org1 and peer0.org2# peer channel getinfo -c mychannel
Now our First Network has a new block containing the Org3 configuration.

3. Bring up Peers of Org3 and Join mychannel

// a new terminal for Org3cli$ docker-compose -f docker-compose-org3.yaml up -d
// Org3cli$ docker exec -it Org3cli bash# export ORDERER_CA=/opt/gopath/src/ && export CHANNEL_NAME=mychannel
// cli for peer channel fetch 0 mychannel.block -o -c $CHANNEL_NAME --tls --cafile $ORDERER_CA
// my localhost$ docker cp cli:/opt/gopath/src/ .$ docker cp mychannel.block Org3cli:/opt/gopath/src/
// Org3cli# peer channel join -b mychannel.block
// Org3cli# CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/ peer channel join -b mychannel.block
// Org3cli# peer channel getinfo -c mychannel

4. Chaincode operations after Org3 is part of the network

// cli for peer chaincode install -n mycc -v 2.0 -p cli for peer chaincode install -n mycc -v 2.0 -p Org3cli# peer chaincode install -n mycc -v 2.0 -p
// cli for peer chaincode upgrade -o —-tls $CORE_PEER_TLS_ENABLED —-cafile $ORDERER_CA -C $CHANNEL_NAME -n mycc -v 2.0 -c '{"Args":["init","a","90","b","210"]}' -P "OR ('Org1MSP.peer','Org2MSP.peer','Org3MSP.peer')"
// Org3cli# peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}'
// Org3cli# peer chaincode invoke -o --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME -n mycc -c '{"Args":["invoke","a","b","10"]}'// cli for peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}'

5. Clean Up

// in first-network directory$ ./ down


Visit for all my works. Reach me on or follow me @kctheservant in Twitter.

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store