github.com/kaituanwang/hyperledger@v2.0.1+incompatible/docs/source/commands/peerchannel.md (about) 1 # peer channel 2 3 The `peer channel` command allows administrators to perform channel related 4 operations on a peer, such as joining a channel or listing the channels to which 5 a peer is joined. 6 7 ## Syntax 8 9 The `peer channel` command has the following subcommands: 10 11 * create 12 * fetch 13 * getinfo 14 * join 15 * list 16 * signconfigtx 17 * update 18 19 ## peer channel 20 ``` 21 Operate a channel: create|fetch|join|list|update|signconfigtx|getinfo. 22 23 Usage: 24 peer channel [command] 25 26 Available Commands: 27 create Create a channel 28 fetch Fetch a block 29 getinfo get blockchain information of a specified channel. 30 join Joins the peer to a channel. 31 list List of channels peer has joined. 32 signconfigtx Signs a configtx update. 33 update Send a configtx update. 34 35 Flags: 36 --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint 37 --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint 38 --clientauth Use mutual TLS when communicating with the orderer endpoint 39 --connTimeout duration Timeout for client to connect (default 3s) 40 -h, --help help for channel 41 --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint 42 -o, --orderer string Ordering service endpoint 43 --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer. 44 --tls Use TLS when communicating with the orderer endpoint 45 46 Use "peer channel [command] --help" for more information about a command. 47 ``` 48 49 50 ## peer channel create 51 ``` 52 Create a channel and write the genesis block to a file. 53 54 Usage: 55 peer channel create [flags] 56 57 Flags: 58 -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.-]* 59 -f, --file string Configuration transaction file generated by a tool such as configtxgen for submitting to orderer 60 -h, --help help for create 61 --outputBlock string The path to write the genesis block for the channel. (default ./<channelID>.block) 62 -t, --timeout duration Channel creation timeout (default 10s) 63 64 Global Flags: 65 --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint 66 --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint 67 --clientauth Use mutual TLS when communicating with the orderer endpoint 68 --connTimeout duration Timeout for client to connect (default 3s) 69 --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint 70 -o, --orderer string Ordering service endpoint 71 --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer. 72 --tls Use TLS when communicating with the orderer endpoint 73 ``` 74 75 76 ## peer channel fetch 77 ``` 78 Fetch a specified block, writing it to a file. 79 80 Usage: 81 peer channel fetch <newest|oldest|config|(number)> [outputfile] [flags] 82 83 Flags: 84 --bestEffort Whether fetch requests should ignore errors and return blocks on a best effort basis 85 -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.-]* 86 -h, --help help for fetch 87 88 Global Flags: 89 --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint 90 --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint 91 --clientauth Use mutual TLS when communicating with the orderer endpoint 92 --connTimeout duration Timeout for client to connect (default 3s) 93 --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint 94 -o, --orderer string Ordering service endpoint 95 --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer. 96 --tls Use TLS when communicating with the orderer endpoint 97 ``` 98 99 100 ## peer channel getinfo 101 ``` 102 get blockchain information of a specified channel. Requires '-c'. 103 104 Usage: 105 peer channel getinfo [flags] 106 107 Flags: 108 -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.-]* 109 -h, --help help for getinfo 110 111 Global Flags: 112 --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint 113 --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint 114 --clientauth Use mutual TLS when communicating with the orderer endpoint 115 --connTimeout duration Timeout for client to connect (default 3s) 116 --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint 117 -o, --orderer string Ordering service endpoint 118 --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer. 119 --tls Use TLS when communicating with the orderer endpoint 120 ``` 121 122 123 ## peer channel join 124 ``` 125 Joins the peer to a channel. 126 127 Usage: 128 peer channel join [flags] 129 130 Flags: 131 -b, --blockpath string Path to file containing genesis block 132 -h, --help help for join 133 134 Global Flags: 135 --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint 136 --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint 137 --clientauth Use mutual TLS when communicating with the orderer endpoint 138 --connTimeout duration Timeout for client to connect (default 3s) 139 --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint 140 -o, --orderer string Ordering service endpoint 141 --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer. 142 --tls Use TLS when communicating with the orderer endpoint 143 ``` 144 145 146 ## peer channel list 147 ``` 148 List of channels peer has joined. 149 150 Usage: 151 peer channel list [flags] 152 153 Flags: 154 -h, --help help for list 155 156 Global Flags: 157 --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint 158 --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint 159 --clientauth Use mutual TLS when communicating with the orderer endpoint 160 --connTimeout duration Timeout for client to connect (default 3s) 161 --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint 162 -o, --orderer string Ordering service endpoint 163 --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer. 164 --tls Use TLS when communicating with the orderer endpoint 165 ``` 166 167 168 ## peer channel signconfigtx 169 ``` 170 Signs the supplied configtx update file in place on the filesystem. Requires '-f'. 171 172 Usage: 173 peer channel signconfigtx [flags] 174 175 Flags: 176 -f, --file string Configuration transaction file generated by a tool such as configtxgen for submitting to orderer 177 -h, --help help for signconfigtx 178 179 Global Flags: 180 --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint 181 --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint 182 --clientauth Use mutual TLS when communicating with the orderer endpoint 183 --connTimeout duration Timeout for client to connect (default 3s) 184 --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint 185 -o, --orderer string Ordering service endpoint 186 --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer. 187 --tls Use TLS when communicating with the orderer endpoint 188 ``` 189 190 191 ## peer channel update 192 ``` 193 Signs and sends the supplied configtx update file to the channel. Requires '-f', '-o', '-c'. 194 195 Usage: 196 peer channel update [flags] 197 198 Flags: 199 -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.-]* 200 -f, --file string Configuration transaction file generated by a tool such as configtxgen for submitting to orderer 201 -h, --help help for update 202 203 Global Flags: 204 --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint 205 --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint 206 --clientauth Use mutual TLS when communicating with the orderer endpoint 207 --connTimeout duration Timeout for client to connect (default 3s) 208 --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint 209 -o, --orderer string Ordering service endpoint 210 --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer. 211 --tls Use TLS when communicating with the orderer endpoint 212 ``` 213 214 ## Example Usage 215 216 ### peer channel create examples 217 218 Here's an example that uses the `--orderer` global flag on the `peer channel 219 create` command. 220 221 * Create a sample channel `mychannel` defined by the configuration transaction 222 contained in file `./createchannel.tx`. Use the orderer at `orderer.example.com:7050`. 223 224 ``` 225 peer channel create -c mychannel -f ./createchannel.tx --orderer orderer.example.com:7050 226 227 2018-02-25 08:23:57.548 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized 228 2018-02-25 08:23:57.626 UTC [channelCmd] InitCmdFactory -> INFO 019 Endorser and orderer connections initialized 229 2018-02-25 08:23:57.834 UTC [channelCmd] readBlock -> INFO 020 Received block: 0 230 2018-02-25 08:23:57.835 UTC [main] main -> INFO 021 Exiting..... 231 232 ``` 233 234 Block 0 is returned indicating that the channel has been successfully created. 235 236 Here's an example of the `peer channel create` command option. 237 238 * Create a new channel `mychannel` for the network, using the orderer at ip 239 address `orderer.example.com:7050`. The configuration update transaction 240 required to create this channel is defined the file `./createchannel.tx`. 241 Wait 30 seconds for the channel to be created. 242 243 ``` 244 peer channel create -c mychannel --orderer orderer.example.com:7050 -f ./createchannel.tx -t 30s 245 246 2018-02-23 06:31:58.568 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized 247 2018-02-23 06:31:58.669 UTC [channelCmd] InitCmdFactory -> INFO 019 Endorser and orderer connections initialized 248 2018-02-23 06:31:58.877 UTC [channelCmd] readBlock -> INFO 020 Received block: 0 249 2018-02-23 06:31:58.878 UTC [main] main -> INFO 021 Exiting..... 250 251 ls -l 252 253 -rw-r--r-- 1 root root 11982 Feb 25 12:24 mychannel.block 254 255 ``` 256 257 You can see that channel `mychannel` has been successfully created, as 258 indicated in the output where block 0 (zero) is added to the blockchain for 259 this channel and returned to the peer, where it is stored in the local 260 directory as `mychannel.block`. 261 262 Block zero is often called the *genesis block* as it provides the starting 263 configuration for the channel. All subsequent updates to the channel will be 264 captured as configuration blocks on the channel's blockchain, each of which 265 supersedes the previous configuration. 266 267 ### peer channel fetch example 268 269 Here's some examples of the `peer channel fetch` command. 270 271 * Using the `newest` option to retrieve the most recent channel block, and 272 store it in the file `mychannel.block`. 273 274 ``` 275 peer channel fetch newest mychannel.block -c mychannel --orderer orderer.example.com:7050 276 277 2018-02-25 13:10:16.137 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized 278 2018-02-25 13:10:16.144 UTC [channelCmd] readBlock -> INFO 00a Received block: 32 279 2018-02-25 13:10:16.145 UTC [main] main -> INFO 00b Exiting..... 280 281 ls -l 282 283 -rw-r--r-- 1 root root 11982 Feb 25 13:10 mychannel.block 284 285 ``` 286 287 You can see that the retrieved block is number 32, and that the information 288 has been written to the file `mychannel.block`. 289 290 * Using the `(block number)` option to retrieve a specific block -- in this 291 case, block number 16 -- and store it in the default block file. 292 293 ``` 294 peer channel fetch 16 -c mychannel --orderer orderer.example.com:7050 295 296 2018-02-25 13:46:50.296 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized 297 2018-02-25 13:46:50.302 UTC [channelCmd] readBlock -> INFO 00a Received block: 16 298 2018-02-25 13:46:50.302 UTC [main] main -> INFO 00b Exiting..... 299 300 ls -l 301 302 -rw-r--r-- 1 root root 11982 Feb 25 13:10 mychannel.block 303 -rw-r--r-- 1 root root 4783 Feb 25 13:46 mychannel_16.block 304 305 ``` 306 307 You can see that the retrieved block is number 16, and that the information 308 has been written to the default file `mychannel_16.block`. 309 310 For configuration blocks, the block file can be decoded using the 311 [`configtxlator` command](./configtxlator.html). See this command for an example 312 of decoded output. User transaction blocks can also be decoded, but a user 313 program must be written to do this. 314 315 ### peer channel getinfo example 316 317 Here's an example of the `peer channel getinfo` command. 318 319 * Get information about the local peer for channel `mychannel`. 320 321 ``` 322 peer channel getinfo -c mychannel 323 324 2018-02-25 15:15:44.135 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized 325 Blockchain info: {"height":5,"currentBlockHash":"JgK9lcaPUNmFb5Mp1qe1SVMsx3o/22Ct4+n5tejcXCw=","previousBlockHash":"f8lZXoAn3gF86zrFq7L1DzW2aKuabH9Ow6SIE5Y04a4="} 326 2018-02-25 15:15:44.139 UTC [main] main -> INFO 006 Exiting..... 327 328 ``` 329 330 You can see that the latest block for channel `mychannel` is block 5. You 331 can also see the cryptographic hashes for the most recent blocks in the 332 channel's blockchain. 333 334 ### peer channel join example 335 336 Here's an example of the `peer channel join` command. 337 338 * Join a peer to the channel defined in the genesis block identified by the file 339 `./mychannel.genesis.block`. In this example, the channel block was 340 previously retrieved by the `peer channel fetch` command. 341 342 ``` 343 peer channel join -b ./mychannel.genesis.block 344 345 2018-02-25 12:25:26.511 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized 346 2018-02-25 12:25:26.571 UTC [channelCmd] executeJoin -> INFO 006 Successfully submitted proposal to join channel 347 2018-02-25 12:25:26.571 UTC [main] main -> INFO 007 Exiting..... 348 349 ``` 350 351 You can see that the peer has successfully made a request to join the channel. 352 353 ### peer channel list example 354 355 Here's an example of the `peer channel list` command. 356 357 * List the channels to which a peer is joined. 358 359 ``` 360 peer channel list 361 362 2018-02-25 14:21:20.361 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized 363 Channels peers has joined: 364 mychannel 365 2018-02-25 14:21:20.372 UTC [main] main -> INFO 006 Exiting..... 366 367 ``` 368 369 You can see that the peer is joined to channel `mychannel`. 370 371 ### peer channel signconfigtx example 372 373 Here's an example of the `peer channel signconfigtx` command. 374 375 * Sign the `channel update` transaction defined in the file 376 `./updatechannel.tx`. The example lists the configuration transaction file 377 before and after the command. 378 379 ``` 380 ls -l 381 382 -rw-r--r-- 1 anthonyodowd staff 284 25 Feb 18:16 updatechannel.tx 383 384 peer channel signconfigtx -f updatechannel.tx 385 386 2018-02-25 18:16:44.456 GMT [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized 387 2018-02-25 18:16:44.459 GMT [main] main -> INFO 002 Exiting..... 388 389 ls -l 390 391 -rw-r--r-- 1 anthonyodowd staff 2180 25 Feb 18:16 updatechannel.tx 392 393 ``` 394 395 You can see that the peer has successfully signed the configuration 396 transaction by the increase in the size of the file `updatechannel.tx` from 397 284 bytes to 2180 bytes. 398 399 ### peer channel update example 400 401 Here's an example of the `peer channel update` command. 402 403 * Update the channel `mychannel` using the configuration transaction defined in 404 the file `./updatechannel.tx`. Use the orderer at ip address 405 `orderer.example.com:7050` to send the configuration transaction to all peers 406 in the channel to update their copy of the channel configuration. 407 408 ``` 409 peer channel update -c mychannel -f ./updatechannel.tx -o orderer.example.com:7050 410 411 2018-02-23 06:32:11.569 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized 412 2018-02-23 06:32:11.626 UTC [main] main -> INFO 010 Exiting..... 413 414 ``` 415 416 At this point, the channel `mychannel` has been successfully updated. 417 418 <a rel="license" href="http://creativecommons.org/licenses/by/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by/4.0/88x31.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>.