Introduction
This article uses the configtxgen tool to create a channel on a Hyperledger Fabric v2.2 network deployed on Chainstack. For the method used in this article, see Create a channel with a system channel (legacy).
This article covers first creating a channel in a network with one organization and then with multiple organizations.
Network with one organization
Create a configtx.yaml file with your network configuration
Create a configtx.yaml file with the following contents:
where
- ORDERER_NAME — the name of the orderer for your network. In the platform UI, navigate to your network; click Service nodes > Orderer > Orderer name.
- NETWORK_ID — the ID of your Hyperledger Fabric network. The network ID is part of the link that you get when opening your deployed network in your browser. For example, in https://chainstack.com/projects/PR-123-456/networks/NW-123-456-7 the network ID is nw-123-456-7.
- NAME_ORGANIZATION_NAME-ORD — the name value field for the organization and orderer name. Should be replaced with Name: ORGANIZATION_NAME-ord where ORGANIZATION_NAME is in lower case. For example, Name: rg-123-456-ord
- NAME_ORGANIZATION_NAME — the name value field for the organization name. Should be replaced with Name: ORGANIZATION_NAME where ORGANIZATION_NAME is in lower case. For example, Name: rg-123-456
- ORGANIZATION_NAME — the name of your organization. See your organization name in the settings.
- PEER_NAME — the name of your peer. In the platform UI, navigate to your peer; click Access and credentials > Peer name.
- MOUNT_DIRECTORY — the name of the directory that you will use as mount point in the next step.
- NEW_CHANNEL — the name you want to give to the channel that you will create.
Connect to your peer
Connect to your peer as described in Chainstack Docs: Interaction tools.
Before you mount the directory, make sure you put the previously created configtx.yaml file in the directory.
Create and join the channel
At this point, you should be connected to your peer in the Docker container.
Change to the mounted directory:
# cd /data
/data # ls
configtx.yaml msp peers users
ca configtx.yaml nd-123-456-789-cert.pem tlsca
Run configtxgen:
configtxgen -profile NEW_CHANNEL -outputCreateChannelTx ./NEW_CHANNEL.tx -channelID NEW_CHANNEL -configPath .
where
- NEW_CHANNEL — the name of the channel you have provided in the configtx.yaml file.
Create the channel:
peer channel create -c NEW_CHANNEL --tls --cafile $ORDERER_CA -o $ORDERER_ADDRESS -f ./NEW_CHANNEL.tx
where
- NEW_CHANNEL — the name of the channel you have provided in the configtx.yaml file.
Create the channel:
peer channel join -b ./NEW_CHANNEL.block
where
- NEW_CHANNEL — the name of the channel you have provided in the configtx.yaml file.
Network with multiple organizations
Create a configtx.yaml file with your network configuration
Create a configtx.yaml file with the following contents:
where
- ORDERER_NAME — the name of the orderer for your network. In the platform UI, navigate to your network; click Service nodes > Orderer > Orderer name.
- NETWORK_ID — the ID of your Hyperledger Fabric network. The network ID is part of the link that you get when opening your deployed network in your browser. For example, in https://chainstack.com/projects/PR-123-456/networks/NW-123-456-7 the network ID is nw-123-456-7.
- NAME_ORGANIZATION_NAME-ORD — the name value field for the first organization and orderer name. Should be replaced with Name: ORGANIZATION_NAME-ord where ORGANIZATION_NAME is in lower case. For example, Name: rg-123-456-ord
- NAME_ORGANIZATION_NAME — the name value field for the first organization name. Should be replaced with Name: ORGANIZATION_NAME where ORGANIZATION_NAME is in lower case. For example, Name: rg-123-456
- ORGANIZATION_NAME — the name of the first organization. See your organization name in the settings.
- PEER_NAME — the name of the peer of the first organization. In the platform UI, navigate to your peer; click Access and credentials > Peer name.
- MOUNT_DIRECTORY — the name of the directory that you will use as mount point in the next step.
- NEW_CHANNEL — the name you want to give to the channel that you will create.
- PEER_02_NAME — the name of the peer of the second organization. In the platform UI, navigate to your peer; click Access and credentials > Peer name.
- NAME_ORGANIZATION_02_NAME — the name value field for the second organization name. Should be replaced with Name: ORGANIZATION_NAME where ORGANIZATION_NAME is in lower case. For example, Name: rg-123-456
- ORGANIZATION_02_NAME — the name of the second organization. See your organization name in the settings.
- NAME_ORGANIZATION_NAME — the name value field for the second organization name. Should be replaced with Name: ORGANIZATION_NAME where ORGANIZATION_NAME is in lower case. For example, Name: rg-123-456
Connect to the peer of the first organization
Connect to your peer as described in Chainstack Docs: Interaction tools.
Before you mount the directory, make sure you have the following files and directories there:
- configtx.yaml — the previously created configtx.yaml file in the directory
- msp01 — rename the existing directory msp to msp01. This is the directory that holds public certificates for your first organization.
- msp02 — in the second organization export, rename the msp directory to msp02 and put it in the directory of the first organization.
Create and join the channel
At this point, you should be connected to your peer in the Docker container.
Change to the mounted directory:
# cd /data
/data # ls
configtx.yaml msp peers users
ca configtx.yaml nd-123-456-789-cert.pem tlsca
Run configtxgen:
configtxgen -profile NEW_CHANNEL -outputCreateChannelTx ./NEW_CHANNEL.tx -channelID NEW_CHANNEL -configPath .
where
- NEW_CHANNEL — the name of the channel you have provided in the configtx.yaml file.
Create the channel:
peer channel create -c NEW_CHANNEL --tls --cafile $ORDERER_CA -o $ORDERER_ADDRESS -f ./NEW_CHANNEL.tx
where
- NEW_CHANNEL — the name of the channel you have provided in the configtx.yaml file.
Join the channel:
peer channel join -b ./NEW_CHANNEL.block
where
- NEW_CHANNEL — the name of the channel you have provided in the configtx.yaml file.
You have now created a channel and joined the channel with the peer of the first organization.
Copy the genesis block from the first organization to the second organization
In the directory of the first organization, you now have the NEW_CHANNEL.block file.
Copy this file to the directory of the second organization on your local machine.
Connect to the peer of the second organization
Connect to your peer as described in Chainstack Docs: Interaction tools.
Before you mount the directory, make sure you have the the NEW_CHANNEL.block file there.
Join the channel
peer channel join -b ./NEW_CHANNEL.block
where
- NEW_CHANNEL — the name of the channel you have previously created.
Comments
0 comments
Article is closed for comments.