peer channel

The peer channel command allows administrators to perform channel related operations on a peer, such as joining a channel or listing the channels to which a peer is joined.

Syntax

The peer channel command has the following subcommands:

  • create

  • fetch

  • getinfo

  • join

  • joinbysnapshot

  • joinbysnapshotstatus

  • list

  • signconfigtx

  • update

peer channel

  1. Operate a channel: create|fetch|join|joinbysnapshot|joinbysnapshotstatus|list|update|signconfigtx|getinfo.
  2. Usage:
  3. peer channel [command]
  4. Available Commands:
  5. create Create a channel
  6. fetch Fetch a block
  7. getinfo get blockchain information of a specified channel.
  8. join Joins the peer to a channel.
  9. joinbysnapshot Joins the peer to a channel by the specified snapshot
  10. joinbysnapshotstatus Query if joinbysnapshot is running for any channel
  11. list List of channels peer has joined.
  12. signconfigtx Signs a configtx update.
  13. update Send a configtx update.
  14. Flags:
  15. --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
  16. --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
  17. --clientauth Use mutual TLS when communicating with the orderer endpoint
  18. --connTimeout duration Timeout for client to connect (default 3s)
  19. -h, --help help for channel
  20. --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
  21. -o, --orderer string Ordering service endpoint
  22. --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer
  23. --tls Use TLS when communicating with the orderer endpoint
  24. --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint
  25. Use "peer channel [command] --help" for more information about a command.

peer channel create

  1. Create a channel and write the genesis block to a file.
  2. Usage:
  3. peer channel create [flags]
  4. Flags:
  5. -c, --channelID string In case of a newChain command, the channel ID to create. It must be all lower case, less than 250 characters long and match the regular expression: [a-z][a-z0-9.-]*
  6. -f, --file string Configuration transaction file generated by a tool such as configtxgen for submitting to orderer
  7. -h, --help help for create
  8. --outputBlock string The path to write the genesis block for the channel. (default ./<channelID>.block)
  9. -t, --timeout duration Channel creation timeout (default 10s)
  10. Global Flags:
  11. --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
  12. --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
  13. --clientauth Use mutual TLS when communicating with the orderer endpoint
  14. --connTimeout duration Timeout for client to connect (default 3s)
  15. --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
  16. -o, --orderer string Ordering service endpoint
  17. --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer
  18. --tls Use TLS when communicating with the orderer endpoint
  19. --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint

peer channel fetch

  1. Fetch a specified block, writing it to a file.
  2. Usage:
  3. peer channel fetch <newest|oldest|config|(number)> [outputfile] [flags]
  4. Flags:
  5. --bestEffort Whether fetch requests should ignore errors and return blocks on a best effort basis
  6. -c, --channelID string In case of a newChain command, the channel ID to create. It must be all lower case, less than 250 characters long and match the regular expression: [a-z][a-z0-9.-]*
  7. -h, --help help for fetch
  8. Global Flags:
  9. --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
  10. --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
  11. --clientauth Use mutual TLS when communicating with the orderer endpoint
  12. --connTimeout duration Timeout for client to connect (default 3s)
  13. --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
  14. -o, --orderer string Ordering service endpoint
  15. --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer
  16. --tls Use TLS when communicating with the orderer endpoint
  17. --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint

peer channel getinfo

  1. get blockchain information of a specified channel. Requires '-c'.
  2. Usage:
  3. peer channel getinfo [flags]
  4. Flags:
  5. -c, --channelID string In case of a newChain command, the channel ID to create. It must be all lower case, less than 250 characters long and match the regular expression: [a-z][a-z0-9.-]*
  6. -h, --help help for getinfo
  7. Global Flags:
  8. --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
  9. --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
  10. --clientauth Use mutual TLS when communicating with the orderer endpoint
  11. --connTimeout duration Timeout for client to connect (default 3s)
  12. --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
  13. -o, --orderer string Ordering service endpoint
  14. --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer
  15. --tls Use TLS when communicating with the orderer endpoint
  16. --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint

peer channel join

  1. Joins the peer to a channel.
  2. Usage:
  3. peer channel join [flags]
  4. Flags:
  5. -b, --blockpath string Path to file containing genesis block
  6. -h, --help help for join
  7. Global Flags:
  8. --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
  9. --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
  10. --clientauth Use mutual TLS when communicating with the orderer endpoint
  11. --connTimeout duration Timeout for client to connect (default 3s)
  12. --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
  13. -o, --orderer string Ordering service endpoint
  14. --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer
  15. --tls Use TLS when communicating with the orderer endpoint
  16. --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint

peer channel joinbysnapshot

  1. Joins the peer to a channel by the specified snapshot
  2. Usage:
  3. peer channel joinbysnapshot [flags]
  4. Flags:
  5. -h, --help help for joinbysnapshot
  6. --snapshotpath string Path to the snapshot directory
  7. Global Flags:
  8. --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
  9. --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
  10. --clientauth Use mutual TLS when communicating with the orderer endpoint
  11. --connTimeout duration Timeout for client to connect (default 3s)
  12. --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
  13. -o, --orderer string Ordering service endpoint
  14. --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer
  15. --tls Use TLS when communicating with the orderer endpoint
  16. --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint

peer channel joinbysnapshotstatus

  1. Query if joinbysnapshot is running for any channel
  2. Usage:
  3. peer channel joinbysnapshotstatus [flags]
  4. Flags:
  5. -h, --help help for joinbysnapshotstatus
  6. Global Flags:
  7. --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
  8. --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
  9. --clientauth Use mutual TLS when communicating with the orderer endpoint
  10. --connTimeout duration Timeout for client to connect (default 3s)
  11. --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
  12. -o, --orderer string Ordering service endpoint
  13. --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer
  14. --tls Use TLS when communicating with the orderer endpoint
  15. --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint

peer channel list

  1. List of channels peer has joined.
  2. Usage:
  3. peer channel list [flags]
  4. Flags:
  5. -h, --help help for list
  6. Global Flags:
  7. --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
  8. --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
  9. --clientauth Use mutual TLS when communicating with the orderer endpoint
  10. --connTimeout duration Timeout for client to connect (default 3s)
  11. --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
  12. -o, --orderer string Ordering service endpoint
  13. --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer
  14. --tls Use TLS when communicating with the orderer endpoint
  15. --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint

peer channel signconfigtx

  1. Signs the supplied configtx update file in place on the filesystem. Requires '-f'.
  2. Usage:
  3. peer channel signconfigtx [flags]
  4. Flags:
  5. -f, --file string Configuration transaction file generated by a tool such as configtxgen for submitting to orderer
  6. -h, --help help for signconfigtx
  7. Global Flags:
  8. --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
  9. --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
  10. --clientauth Use mutual TLS when communicating with the orderer endpoint
  11. --connTimeout duration Timeout for client to connect (default 3s)
  12. --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
  13. -o, --orderer string Ordering service endpoint
  14. --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer
  15. --tls Use TLS when communicating with the orderer endpoint
  16. --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint

peer channel update

  1. Signs and sends the supplied configtx update file to the channel. Requires '-f', '-o', '-c'.
  2. Usage:
  3. peer channel update [flags]
  4. Flags:
  5. -c, --channelID string In case of a newChain command, the channel ID to create. It must be all lower case, less than 250 characters long and match the regular expression: [a-z][a-z0-9.-]*
  6. -f, --file string Configuration transaction file generated by a tool such as configtxgen for submitting to orderer
  7. -h, --help help for update
  8. Global Flags:
  9. --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
  10. --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
  11. --clientauth Use mutual TLS when communicating with the orderer endpoint
  12. --connTimeout duration Timeout for client to connect (default 3s)
  13. --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
  14. -o, --orderer string Ordering service endpoint
  15. --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer
  16. --tls Use TLS when communicating with the orderer endpoint
  17. --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint

Example Usage

peer channel create examples

Here’s an example that uses the --orderer global flag on the peer channel create command.

  • Create a sample channel mychannel defined by the configuration transaction contained in file ./createchannel.tx. Use the orderer at orderer.example.com:7050.

    1. peer channel create -c mychannel -f ./createchannel.tx --orderer orderer.example.com:7050
    2. 2018-02-25 08:23:57.548 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
    3. 2018-02-25 08:23:57.626 UTC [channelCmd] InitCmdFactory -> INFO 019 Endorser and orderer connections initialized
    4. 2018-02-25 08:23:57.834 UTC [channelCmd] readBlock -> INFO 020 Received block: 0
    5. 2018-02-25 08:23:57.835 UTC [main] main -> INFO 021 Exiting.....

    Block 0 is returned indicating that the channel has been successfully created.

Here’s an example of the peer channel create command option.

  • Create a new channel mychannel for the network, using the orderer at ip address orderer.example.com:7050. The configuration update transaction required to create this channel is defined the file ./createchannel.tx. Wait 30 seconds for the channel to be created.

    1. peer channel create -c mychannel --orderer orderer.example.com:7050 -f ./createchannel.tx -t 30s
    2. 2018-02-23 06:31:58.568 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
    3. 2018-02-23 06:31:58.669 UTC [channelCmd] InitCmdFactory -> INFO 019 Endorser and orderer connections initialized
    4. 2018-02-23 06:31:58.877 UTC [channelCmd] readBlock -> INFO 020 Received block: 0
    5. 2018-02-23 06:31:58.878 UTC [main] main -> INFO 021 Exiting.....
    6. ls -l
    7. -rw-r--r-- 1 root root 11982 Feb 25 12:24 mychannel.block

    You can see that channel mychannel has been successfully created, as indicated in the output where block 0 (zero) is added to the blockchain for this channel and returned to the peer, where it is stored in the local directory as mychannel.block.

    Block zero is often called the genesis block as it provides the starting configuration for the channel. All subsequent updates to the channel will be captured as configuration blocks on the channel’s blockchain, each of which supersedes the previous configuration.

peer channel fetch example

Here’s some examples of the peer channel fetch command.

  • Using the newest option to retrieve the most recent channel block, and store it in the file mychannel.block.

    1. peer channel fetch newest mychannel.block -c mychannel --orderer orderer.example.com:7050
    2. 2018-02-25 13:10:16.137 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
    3. 2018-02-25 13:10:16.144 UTC [channelCmd] readBlock -> INFO 00a Received block: 32
    4. 2018-02-25 13:10:16.145 UTC [main] main -> INFO 00b Exiting.....
    5. ls -l
    6. -rw-r--r-- 1 root root 11982 Feb 25 13:10 mychannel.block

    You can see that the retrieved block is number 32, and that the information has been written to the file mychannel.block.

  • Using the (block number) option to retrieve a specific block – in this case, block number 16 – and store it in the default block file.

    1. peer channel fetch 16 -c mychannel --orderer orderer.example.com:7050
    2. 2018-02-25 13:46:50.296 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
    3. 2018-02-25 13:46:50.302 UTC [channelCmd] readBlock -> INFO 00a Received block: 16
    4. 2018-02-25 13:46:50.302 UTC [main] main -> INFO 00b Exiting.....
    5. ls -l
    6. -rw-r--r-- 1 root root 11982 Feb 25 13:10 mychannel.block
    7. -rw-r--r-- 1 root root 4783 Feb 25 13:46 mychannel_16.block

    You can see that the retrieved block is number 16, and that the information has been written to the default file mychannel_16.block.

    For configuration blocks, the block file can be decoded using the configtxlator command. See this command for an example of decoded output. User transaction blocks can also be decoded, but a user program must be written to do this.

peer channel getinfo example

Here’s an example of the peer channel getinfo command.

  • Get information about the local peer for channel mychannel.

    1. peer channel getinfo -c mychannel
    2. 2018-02-25 15:15:44.135 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
    3. Blockchain info: {"height":5,"currentBlockHash":"JgK9lcaPUNmFb5Mp1qe1SVMsx3o/22Ct4+n5tejcXCw=","previousBlockHash":"f8lZXoAn3gF86zrFq7L1DzW2aKuabH9Ow6SIE5Y04a4="}
    4. 2018-02-25 15:15:44.139 UTC [main] main -> INFO 006 Exiting.....

    You can see that the latest block for channel mychannel is block 5. You can also see the cryptographic hashes for the most recent blocks in the channel’s blockchain.

peer channel join example

Here’s an example of the peer channel join command.

  • Join a peer to the channel defined in the genesis block identified by the file ./mychannel.genesis.block. In this example, the channel block was previously retrieved by the peer channel fetch command.

    1. peer channel join -b ./mychannel.genesis.block
    2. 2018-02-25 12:25:26.511 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
    3. 2018-02-25 12:25:26.571 UTC [channelCmd] executeJoin -> INFO 006 Successfully submitted proposal to join channel
    4. 2018-02-25 12:25:26.571 UTC [main] main -> INFO 007 Exiting.....

    You can see that the peer has successfully made a request to join the channel.

peer channel joinbysnapshot example

Here’s an example of the peer channel joinbysnapshot command.

  • Join a peer to the channel from a snapshot identified by the directory /snapshots/completed/testchannel/1000. The snapshot was previously created on a different peer.

    1. peer channel joinbysnapshot --snapshotpath /snapshots/completed/testchannel/1000
    2. 2020-10-12 11:41:45.442 EDT [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
    3. 2020-10-12 11:41:45.444 EDT [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
    4. 2020-10-12 11:41:45.444 EDT [channelCmd] joinBySnapshot -> INFO 003 The joinbysnapshot operation is in progress. Use "peer channel joinbysnapshotstatus" to check the status.

    You can see that the peer has successfully made a request to join the channel from the specified snapshot. When a joinbysnapshot operation is in progress, you cannot run another peer channel join or peer channel joinbysnapshot simultaneously. To know whether or not a joinbysnapshot operation is in progress, you can call the peer channel joinbysnapshotstatus command.

peer channel joinbysnapshotstatus example

Here are some examples of the peer channel joinbysnapshotstatus command.

  • Query if joinbysnapshot is in progress for any channel. If yes, it returns a message indicating a joinbysnapshot operation is in progress.

    1. peer channel joinbysnapshotstatus
    2. 2020-10-12 11:41:45.952 EDT [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
    3. A joinbysnapshot operation is in progress for snapshot at /snapshots/completed/testchannel/1000
  • If no joinbysnapshot operation is in progress, it returns a message indicating no joinbysnapshot operation is in progress.

    1. peer channel joinbysnapshotstatus
    2. 2020-10-12 11:41:47.922 EDT [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
    3. No joinbysnapshot operation is in progress

peer channel list example

Here’s an example of the peer channel list command.

  • List the channels to which a peer is joined.

    1. peer channel list
    2. 2018-02-25 14:21:20.361 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
    3. Channels peers has joined:
    4. mychannel
    5. 2018-02-25 14:21:20.372 UTC [main] main -> INFO 006 Exiting.....

    You can see that the peer is joined to channel mychannel.

peer channel signconfigtx example

Here’s an example of the peer channel signconfigtx command.

  • Sign the channel update transaction defined in the file ./updatechannel.tx. The example lists the configuration transaction file before and after the command.

    1. ls -l
    2. -rw-r--r-- 1 anthonyodowd staff 284 25 Feb 18:16 updatechannel.tx
    3. peer channel signconfigtx -f updatechannel.tx
    4. 2018-02-25 18:16:44.456 GMT [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
    5. 2018-02-25 18:16:44.459 GMT [main] main -> INFO 002 Exiting.....
    6. ls -l
    7. -rw-r--r-- 1 anthonyodowd staff 2180 25 Feb 18:16 updatechannel.tx

    You can see that the peer has successfully signed the configuration transaction by the increase in the size of the file updatechannel.tx from 284 bytes to 2180 bytes.

peer channel update example

Here’s an example of the peer channel update command.

  • Update the channel mychannel using the configuration transaction defined in the file ./updatechannel.tx. Use the orderer at ip address orderer.example.com:7050 to send the configuration transaction to all peers in the channel to update their copy of the channel configuration.

    1. peer channel update -c mychannel -f ./updatechannel.tx -o orderer.example.com:7050
    2. 2018-02-23 06:32:11.569 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
    3. 2018-02-23 06:32:11.626 UTC [main] main -> INFO 010 Exiting.....

    At this point, the channel mychannel has been successfully updated.

Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.