Add Organizations to Channel in Hyperledger Fabric


Add Organizations to Channel in Hyperledger Fabric

Recipe ID: hsts-r26


Self-paced training

We offer blockchain introduction, Hyperledger for system admin, Ethereum, Solidity, Corda R3, Hyperledger for developers, blockchain cybersecurity and more classes in self-paced video format starting at $60. Click here to learn more and register. For complete self-paced blockchain training, visit our Complete Blockchain Development Training page.


Recipe Overview

Hyperledger Fabric is an open source enterprise-grade platform that leverages a highly-modular and configurable architecture. Hyperledger Fabric is optimized for a broad range of industry use cases, including the finance, banking, healthcare, insurance, and public sectors, as well as supply chains and digital asset management.
For those who are not familiar with Hyperledger project Intro to Hyperledger Family and Hyperledger Blockchain Ecosystem, Hyperledger Design Philosophy and Framework Architecture, The Survey of Hyperledger Fabric Architecture and Components for Blockchain Developers and Overview of Building Blockchain Smart Contracts in Hyperledger articles are strongly recommended.
Hyperledger Fabric supports Smart Contact development in general-purpose programming languages, such as JavaScriptJava, Go, and Node.js. Hyperledger Fabric is also operating under a governance model to build trust between participants on a shared network.
In our previous recipes, we have successfully installed Hyperledger Fabric on an AWS EC2 virtual machine and set up the first Hyperledger Fabric network. We learned the following:

This recipe serves as an extension to the BYFN (previous)recipe. We will demonstrate how to add a new organization – Org3 – to the application's channel (mychannel).

Adding New Organization to Hyperledger Fabric Channel

Since we need add the new organization, Org3, to BYFN, we will first bring up the BYFN network. Follow these steps:

1. Bring up the first network using the following command:

$ cd ~

cd fabric-samples/first-network

 sudo ./byfn.sh generate

sudo ./byfn.sh up

 

2. Execute the script to add Org3 into the mychannel channel:

$ cd ~

cd fabric-samples/first-network

 sudo ./eyfn.sh up

The following screenshot confirms org3 is added to mychannel successfully:
hyperledger fabric development

 

We can test this by running a query against Org3 peer0.
3. To shut down and clean up the network, execute the following:
cd fabric-samples/first-network

sudo ./eyfn.sh down

 sudo ./byfn.sh down

Like what we did in the Building the Fabric network recipe, the eyfn.sh script is a good resource to understand how things work.
We will also look into the command-line steps to see the internal building blocks to add an organization to a channel:
hyperledger fabric development

 

4. Generate the org3 certificates:

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

5. Generate the org3 configuration materials:

configtxgen -printOrg Org3MSP
 

6. Generate and submit the transaction configuration for organization 3:

peer channel fetch config config_block.pb -o orderer.example.com:7050 -c mychannel --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/ crypto/ordererOrganizations/example.com/orderers/ orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem $ configtxlator proto_encode --input config.json 

--type common.Config

$ configtxlator proto_encode --input modified_config.json --type common.Config

$ configtxlator compute_update --channel_id mychannel

--original original_config.pb --updated modified_config.pb $ configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate

7. Configure the transaction to add org3, which has been created:

peer channel signconfigtx -f org3_update_in_envelope.pb 

8. Submit the transaction from a different peer (peer0.org2), who also signs it:

peer channel update -f org3_update_in_envelope.pb -c mychannel -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/ crypto/ordererOrganizations/example.com/orderers/ orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
 

9. Get the org3 peer to join the network:

peer channel fetch 0 mychannel.block -o orderer.example.com:7050 -c mychannel --tls --cafile /opt/gopath/src/github.com/

hyperledger/fabric/peer/crypto/ordererOrganizations/

example.com/orderers/orderer.example.com/ msp/tlscacerts/tlsca.example.com-cert.pem
peer channel join 

-b mychannel.blockcd fabric-samples/first-network

10. Install and update the chaincode:

peer chaincode install -n mycc -v 2.0 -l golang -p github.com/chaincode/chaincode_example02/go/

$ peer chaincode upgrade -o orderer.example.com:7050

--tls true --cafile /opt/gopath/src/github.com/hyperledger/

fabric/peer/crypto/ordererOrganizations/example.com/orderers/

orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

-C mychannel -n mycc -v 2.0 -c

'{"Args":["init","a","90","b","210"]}'

-P 'AND ('\''Org1MSP.peer'\'','\''Org2MSP.peer'\'', '\''Org3MSP.peer'\'')'11. Query peer0 org3:

peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'

 

12. Invoke the transaction to move 10 from a to b again on a different peer:

peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/ crypto/ordererOrganizations/example.com/orderers/ orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/

fabric/peer/crypto/peerOrganizations/org1.example.com/peers/

peer0.org1.example.com/tls/ca.crt

--peerAddresses peer0.org2.example.com:7051

--tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/ fabric/peer/crypto/peerOrganizations/org2.example.com/peers/

peer0.org2.example.com/tls/ca.crt

--peerAddresses peer0.org3.example.com:7051
--tlsRootCertFiles/opt/gopath/src/github.com/hyperledger/ fabric/peer/crypto/peerOrganizations/org3.example.com/peers/ peer0.org3.example.com/tls/ca.crt
-c '{"Args":["invoke","a","b","10"]}'

This concludes how to add an organization to an existing network in a channel. We will look at how to use CouchDB to review transactions in the next recipe.

Following all the previous steps will create our first network, which consists of two organizations, two peers per organization, and single Solo ordering service. In this recipe, we showed you how to add a third organization to an application channel with its own peers to an already running first network, and then join it to the new channel.
When you view the log file, you will be able to see details in the following order:

Updating modification policies or altering batch sizes or any other channel configuration can be updated using the same approach but for this recipe we will focus solely on the integration of a new organization.

Additional Notes
The following block shows the org3-crypto.yaml section for Org3:

# ------------------------------------------------------------------------- -

"PeerOrgs" - Definition of organizations managing peer nodes

------------------------------------------------------------------------

--

PeerOrgs:

-------------------------------------------------------------------------

--

Org3

# -------------------------------------------------------------------------

--

- Name: Org3

Domain: org3.example.com

EnableNodeOUs: true

Template:

Count: 2

Users:

Count: 1

The following block shows the configtx.yaml section for Org3:
########################################################################### ######

#Section: Organizations

 #- This section defines the different organizational identities which will be referenced later in the configuration.

 

#

###########################################################################

#####

Organizations:

- &Org3

# DefaultOrg defines the organization which is used in the sampleconfig

# of the fabric.git development environment

Name: Org3MSP

# ID to load the MSP definition as ID: Org3MSP

MSPDir: crypto-config/peerOrganizations/org3.example.com/msp AnchorPeers:

# AnchorPeers defines the location of peers which can be used for cross org gossip #communication. Note, this value is only

# encoded in the genesis block in the Application section context

Host: peer0.org3.example.com Port: 7051

 

In the next recipe, we will look at how smart contracts work with CouchDB.

Now that we have set up our first network on Hyperledger Fabric and added new organization to a channel, we move on to the following 2 steps or recipes:

The following recipes are excellent resources for installing other Hyperledger tools:
Blockchain Developer Guide- Overview of Hyperledger Explorer and its Development Environment
Blockchain Developer Guide- How to Install Hyperledger Indy and Indy CLI on AWS
Blockchain Hyperledger Composer Business Network Modeling and Environment Setup
Blockchain Developer Guide- How to Install Hyperledger Iroha on AWS
Blockchain Developer Guide- How to Install Hyperledger Burrow on AWS

To conclude this recipe, we like to recommend our Learn Hands-on Blockchain Ethereum Development & Get Certified in 30 Hrs and Blockchain Hyperledger Development in 30 hours courses to those interested in pursuing a blockchain development career. Indeed, as of this writing, Hyperledger Foundation offers the following two Hyperledger certifications: The Certified Hyperledger Fabric Administrator (CHFA) and The Certified Hyperledger Sawtooth Administrator (CHSA), both of which are highly regarded in the industry. Hyperledger Foundation is in the process of creating Hyperledger Developer certification program, which may be released in early or middle of 2020. In short, by taking our hands-on online Hyperledger class, you would be able to obtain CHFA certification.

This tutorial is written by Brian Wu who is our senior Hyperledger instructor in Washington DC. His Hyperledger Cookbook with 40+ hands-on recipes is highly recommended.

Related Training Courses

Hands-on Node.JS, MongoDB and Express.js Training
Advance JavaScript, jQuery Using JSON and Ajax
Learn Hands-on Blockchain Ethereum Development & Get Certified in 30 Hrs
Learn Blockchain Hyperledger Development & Get Certified in 30 Hrs
Become Blockchain Certified Security Architect in 30 hours
Blockchain Certified Solution Architect in 30 hours
Introduction to Python Programming
Object Oriented Programming with UML


Private and Custom Tutoring

We provide private tutoring classes online and offline (at our DC site or your preferred location) with custom curriculum for almost all of our classes for $50 per hour online or $75 per hour in DC. Give us a call or submit our private tutoring registration form to discuss your needs.


View Other Classes!