🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## 1. 释义 创建一个通道,并将创世块写入文件。 ## 2. 使用方法 ``` ~$ peer channel create [flags] ``` ## 3. 命令标志 ``` -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.-]* -f, --file string Configuration transaction file generated by a tool such as configtxgen for submitting to orderer -h, --help help for create --outputBlock string The path to write the genesis block for the channel. (default ./<channelID>.block) -t, --timeout duration Channel creation timeout (default 5s) ``` ### 4. 全局标志: ``` --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint --clientauth Use mutual TLS when communicating with the orderer endpoint --connTimeout duration Timeout for client to connect (default 3s) --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint -o, --orderer string Ordering service endpoint --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer. --tls Use TLS when communicating with the orderer endpoint ``` ## 5. 示例代码 本部分示例在`peer channel create`命令中使用全局标志`--orderer`指定排序器。 下面的示例基于在文件`./createchannel.txn`中的配置交易创建一个通道mychannel,排序器端结点为`orderer.example.com:7050`: ``` ~$ peer channel create -c mychannel -f ./createchannel.txn --orderer orderer.example.com:7050 2018-02-25 08:23:57.548 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized 2018-02-25 08:23:57.626 UTC [channelCmd] InitCmdFactory -> INFO 019 Endorser and orderer connections initialized 2018-02-25 08:23:57.834 UTC [channelCmd] readBlock -> INFO 020 Received block: 0 2018-02-25 08:23:57.835 UTC [main] main -> INFO 021 Exiting..... ``` 返回第0块表示通道已经成功创建。 下面的示例展示`peer channel create`命令选项的用法。在该示例中使用的排序器为orderer.example.com:7050, 创建新的通道mychannel所需要的配置更新交易定义在文件`./createchannel.txn`中,等待30秒以便通道创建 成功: ``` ~$ peer channel create -c mychannel --orderer orderer.example.com:7050 -f ./createchannel.txn -t 30s 2018-02-23 06:31:58.568 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized 2018-02-23 06:31:58.669 UTC [channelCmd] InitCmdFactory -> INFO 019 Endorser and orderer connections initialized 2018-02-23 06:31:58.877 UTC [channelCmd] readBlock -> INFO 020 Received block: 0 2018-02-23 06:31:58.878 UTC [main] main -> INFO 021 Exiting..... ``` 使用ls命令查看创建好的通道创世块: ``` ~$ ls -l -rw-r--r-- 1 root root 11982 Feb 25 12:24 mychannel.block ``` 上面可以看到通道mychannel已经成功创建,第0块已经加入到该通道的区块链中并 返回给节点,该区块在本地文件中存mychannel.block。 第0块通常被称为创世块,因为它提供了通道的起始配置。