Create a test channel

The next step is to create a test channel in which we can deploy some chaincode and verify that everything is working as expected. Run the following command to create the configtx.yaml channel configuration file. The configtx.yaml file contains details of a channel configuration. For more information, see Channel Configuration in the Hyperledger Fabric documentation.

cat <<EOT > configtx.yaml
Organizations:
  - &$MEMBER_NAME
    Name: $MEMBERID
    ID: $MEMBERID
    MSPDir: /opt/home/admin-msp
    AnchorPeers:
      - Host:
        Port:
Capabilities:
  Channel: &ChannelCapabilities
    V1_4_3: true
    V1_3: false
    V1_1: false
  Application: &ApplicationCapabilities
    V1_4_2: true
    V1_3: false
    V1_2: false
    V1_1: false
Application: &ApplicationDefaults
  Organizations:
  Policies:
    Readers:
      Type: ImplicitMeta
      Rule: "ANY Readers"
    Writers:
      Type: ImplicitMeta
      Rule: "ANY Writers"
    Admins:
      Type: ImplicitMeta
      Rule: "MAJORITY Admins"
    LifecycleEndorsement:
      Type: ImplicitMeta
      Rule: "MAJORITY Endorsement"
    Endorsement:
      Type: ImplicitMeta
      Rule: "MAJORITY Endorsement"
  Capabilities:
      <<: *ApplicationCapabilities
Profiles:
  OneOrgChannel:
    Consortium: AWSSystemConsortium
    Policies:
      Readers:
        Type: ImplicitMeta
        Rule: "ANY Readers"
      Writers:
        Type: ImplicitMeta
        Rule: "ANY Writers"
      Admins:
        Type: ImplicitMeta
        Rule: "MAJORITY Admins"
    Application:
      <<: *ApplicationDefaults
      Organizations:
        - *$MEMBER_NAME
EOT

Run the following command to generate the configtx peer block:

docker exec cli configtxgen -outputCreateChannelTx /opt/home/$TEST_CHANNEL_NAME.pb -profile OneOrgChannel -channelID $TEST_CHANNEL_NAME --configPath /opt/home/

The output should look something like this:

2020-10-16 02:23:27.098 UTC [common.tools.configtxgen] main -> INFO 001 Loading configuration
2020-10-16 02:23:27.102 UTC [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /opt/home/configtx.yaml
2020-10-16 02:23:27.105 UTC [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 003 Loaded configuration: /opt/home/configtx.yaml
2020-10-16 02:23:27.105 UTC [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 004 Generating new channel configtx
2020-10-16 02:23:27.106 UTC [common.tools.configtxgen.encoder] NewApplicationOrgGroup -> WARN 005 Default policy emission is deprecated, please include policy specifications for the application org group m-ZCDR2B4WRBG4HINUPN6OPH4RJM in configtx.yaml
2020-10-16 02:23:27.106 UTC [common.tools.configtxgen.encoder] NewApplicationOrgGroup -> WARN 006 Default policy emission is deprecated, please include policy specifications for the application org group m-ZCDR2B4WRBG4HINUPN6OPH4RJM in configtx.yaml
2020-10-16 02:23:27.106 UTC [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 007 Writing new channel tx

Run the following command to create a channel using the variables that you established and the configtx peer block that you created.

docker exec cli peer channel create -c $TEST_CHANNEL_NAME -f "/opt/home/${TEST_CHANNEL_NAME}.pb" -o $ORDERER --cafile /opt/home/managedblockchain-tls-chain.pem --tls

The expected output should look something like:

2020-10-16 02:24:27.149 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2020-10-16 02:24:27.215 UTC [cli.common] readBlock -> INFO 004 Got status: &{NOT_FOUND}
2020-10-16 02:24:27.229 UTC [channelCmd] InitCmdFactory -> INFO 005 Endorser and orderer connections initialized
2020-10-16 02:24:29.572 UTC [cli.common] readBlock -> INFO 006 Received block: 0

Run the following command to join the peer node that you created earlier to the channel. You may see some warnings occur while this command is running. These are expected.

docker exec cli peer channel join -b "${TEST_CHANNEL_NAME}.block" -o $ORDERER --cafile /opt/home/managedblockchain-tls-chain.pem --tls

The expected output should look something like:

2020-10-16 02:25:18.014 UTC [main] InitCmd -> WARN 001 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
2020-10-16 02:25:18.020 UTC [main] SetOrdererEnv -> WARN 002 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
2020-10-16 02:25:18.037 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2020-10-16 02:25:18.314 UTC [channelCmd] executeJoin -> INFO 004 Successfully submitted proposal to join channel