This article describes how to build your own test environment Fabric, which is only used to test and learn the basics of related components. In a production environment, see the official documentation for how to build an environment.

Local environment: Mac

1. One-click deployment environment

In the Fabirc code, a script bootstrap.sh is provided in the scripts directory, which automatically pulls the fabric-samples code and the image associated with deploying fabric. Note that if you want to install the specified version of fabric instead of the latest version, Download the bootstrap.sh script from the corresponding branch of the version. Version 2.2.4 is used for this article

Place the script in the specified file directory as the home directory for subsequent operations, and give bootstrap.sh executable permissions

Mkdir hyfa CD hyfa touch bootstrap.sh Copy the specific bootstrap.sh content in the source code to the preceding file chmod +x bootstrap.sh./bootstrap.shCopy the code

Output from the installation process

 
Clone hyperledger/fabric-samples repo


===> Cloning hyperledger/fabric-samples repo and checkout v2.2.4

Cloning into 'fabric-samples'...

remote: Enumerating objects: 8350, done.

remote: Counting objects: 100% (625/625), done.

remote: Compressing objects: 100% (397/397), done.

remote: Total 8350 (delta 302), reused 450 (delta 217), pack-reused 7725

Receiving objects: 100% (8350/8350), 4.92 MiB | 2.70 MiB/s, done.

Resolving deltas: 100% (4336/4336), done.

error: pathspec 'v2.2.4' did not match any file(s) known to git 


Pull Hyperledger Fabric binaries
 


===> Downloading version 2.2.4 platform specific fabric binaries

===> Downloading:  https://github.com/hyperledger/fabric/releases/download/v2.2.4/hyperledger-fabric-darwin-amd64-2.2.4.tar.gz

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                 Dload  Upload   Total   Spent    Left  Speed

100   681  100   681    0     0   1025      0 --:--:-- --:--:-- --:--:--  1025

100 53.3M  100 53.3M    0     0  2697k      0  0:00:20  0:00:20 --:--:-- 3955k

==> Done.

===> Downloading version 1.5.2 platform specific fabric-ca-client binary

===> Downloading:  https://github.com/hyperledger/fabric-ca/releases/download/v1.5.2/hyperledger-fabric-ca-darwin-amd64-1.5.2.tar.gz

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                 Dload  Upload   Total   Spent    Left  Speed

100   653  100   653    0     0   1108      0 --:--:-- --:--:-- --:--:--  1106

100 25.6M  100 25.6M    0     0  1885k      0  0:00:13  0:00:13 --:--:-- 2923k

==> Done.

\


Pull Hyperledger Fabric docker images

\


FABRIC_IMAGES: peer orderer ccenv tools nodeenv baseos javaenv

===> Pulling fabric Images

====> hyperledger/fabric-peer:2.2.4

2.2.4: Pulling from hyperledger/fabric-peer

a0d0a0d46f8b: Already exists 

39f5dde72e6c: Pull complete 

c60458617bd9: Pull complete 

f03acaa6cd97: Pull complete 

83c51587c9f2: Pull complete 

ae7d6a041376: Pull complete 

Digest: sha256:340025eb11f6537d71efd2820f2a643eb6f48708b0954b0f1592c87e8ce868d2

Status: Downloaded newer image for hyperledger/fabric-peer:2.2.4

docker.io/hyperledger/fabric-peer:2.2.4

====> hyperledger/fabric-orderer:2.2.4

2.2.4: Pulling from hyperledger/fabric-orderer

a0d0a0d46f8b: Already exists 

39f5dde72e6c: Already exists 

2fd7f2d0154d: Pull complete 

f6fd9cda1337: Pull complete 

7d80072c1a36: Pull complete 

8bb955f8010f: Pull complete 

f743c8ee18d0: Pull complete 

Digest: sha256:12331afb762b431b520aec8b3e1fd7b83d5a1b3700deddb86e93a44c3fc2a9d7

Status: Downloaded newer image for hyperledger/fabric-orderer:2.2.4

docker.io/hyperledger/fabric-orderer:2.2.4

====> hyperledger/fabric-ccenv:2.2.4

2.2.4: Pulling from hyperledger/fabric-ccenv

a0d0a0d46f8b: Already exists 

31adcdaf11c8: Pull complete 

b8b176561691: Pull complete 

ffa5077b735b: Pull complete 

2e51fde7a4ad: Pull complete 

88ec7036a0f0: Pull complete 

300acd46ee50: Pull complete 

921211ec1e72: Pull complete 

665fbc77bd34: Pull complete 

Digest: sha256:4ec70e9e41084635db80cc38357dfd6dcaa6fe7b40d84f16ab6366439358bab4

Status: Downloaded newer image for hyperledger/fabric-ccenv:2.2.4

docker.io/hyperledger/fabric-ccenv:2.2.4

====> hyperledger/fabric-tools:2.2.4

2.2.4: Pulling from hyperledger/fabric-tools

a0d0a0d46f8b: Already exists 

31adcdaf11c8: Already exists 

b8b176561691: Already exists 

ffa5077b735b: Already exists 

2e51fde7a4ad: Already exists 

ca55bf76b621: Pull complete 

fcc465d926d3: Pull complete 

025eefba8376: Pull complete 

Digest: sha256:a5f691808466e90942af3f5f72d697cdaa4e545acfc1f645a553986423ef7ea5

Status: Downloaded newer image for hyperledger/fabric-tools:2.2.4

docker.io/hyperledger/fabric-tools:2.2.4

====> hyperledger/fabric-nodeenv:2.2.4

Error response from daemon: manifest for hyperledger/fabric-nodeenv:2.2.4 not found: manifest unknown: manifest unknown

Error response from daemon: No such image: hyperledger/fabric-nodeenv:2.2.4

Error response from daemon: No such image: hyperledger/fabric-nodeenv:2.2.4

====> hyperledger/fabric-baseos:2.2.4

2.2.4: Pulling from hyperledger/fabric-baseos

a0d0a0d46f8b: Already exists 

39f5dde72e6c: Already exists 

bdbe3e81e212: Pull complete 

Digest: sha256:d668bbd0f544eba72e98202236c2ed91b4001f4876be6d90f25e4f6b9b4e421c

Status: Downloaded newer image for hyperledger/fabric-baseos:2.2.4

docker.io/hyperledger/fabric-baseos:2.2.4

====> hyperledger/fabric-javaenv:2.2.4

Error response from daemon: manifest for hyperledger/fabric-javaenv:2.2.4 not found: manifest unknown: manifest unknown

Error response from daemon: No such image: hyperledger/fabric-javaenv:2.2.4

Error response from daemon: No such image: hyperledger/fabric-javaenv:2.2.4

===> Pulling fabric ca Image

====> hyperledger/fabric-ca:1.5.2

1.5.2: Pulling from hyperledger/fabric-ca

a0d0a0d46f8b: Already exists 

ac8258c0aeb1: Pull complete 

6c802cf1fa97: Pull complete 

Digest: sha256:faa3b743d9ed391c30f518a7cc1168160bf335f3bf60ba6aaaf1aa49c1ed023e

Status: Downloaded newer image for hyperledger/fabric-ca:1.5.2

docker.io/hyperledger/fabric-ca:1.5.2

===> List out hyperledger docker images

hyperledger/fabric-ca                   1.5              4ea287b75c63   2 months ago    69.8MB

hyperledger/fabric-ca                   1.5.2            4ea287b75c63   2 months ago    69.8MB

hyperledger/fabric-ca                   latest           4ea287b75c63   2 months ago    69.8MB

hyperledger/fabric-tools                2.2              d32b30082179   2 months ago    429MB

hyperledger/fabric-tools                2.2.4            d32b30082179   2 months ago    429MB

hyperledger/fabric-tools                latest           d32b30082179   2 months ago    429MB

hyperledger/fabric-peer                 2.2              4a3aed7a742c   2 months ago    51.8MB

hyperledger/fabric-peer                 2.2.4            4a3aed7a742c   2 months ago    51.8MB

hyperledger/fabric-peer                 latest           4a3aed7a742c   2 months ago    51.8MB

hyperledger/fabric-orderer              2.2              abf523e91319   2 months ago    35.2MB

hyperledger/fabric-orderer              2.2.4            abf523e91319   2 months ago    35.2MB

hyperledger/fabric-orderer              latest           abf523e91319   2 months ago    35.2MB

hyperledger/fabric-ccenv                2.2              96b8a8b006b4   2 months ago    502MB

hyperledger/fabric-ccenv                2.2.4            96b8a8b006b4   2 months ago    502MB

hyperledger/fabric-ccenv                latest           96b8a8b006b4   2 months ago    502MB

hyperledger/fabric-baseos               2.2              fb6d7b238996   2 months ago    6.87MB

hyperledger/fabric-baseos               2.2.4            fb6d7b238996   2 months ago    6.87MB

hyperledger/fabric-baseos               latest           fb6d7b238996   2 months ago    6.87MB
Copy the code

Add the path of the executable in Fabric-samples to the global:

export PATH=/Users/xxx/workspace/hyfa/fabric-samples/bin:$PATH
Copy the code

2. Test environment setup

cd fabric-samples/test-network
Copy the code

Sh script to start a test environment. For details about how to use the script, see./ net. sh –help

Run./network.sh up, and the script will automatically pull up a test environment for us

➜ test-network git:(master)./network.sh up Starting nodes with CLI timeout of '5' tries and CLI delay of '3' seconds And using database 'leveldb' with crypto from 'cryptogen' LOCAL_VERSION=2.2.4 DOCKER_IMAGE_VERSION=2.2.4 /Users/zhaojunwei/workspace/hyfa/fabric-samples/test-network/.. /bin/cryptogen Generating certificates using cryptogen tool Creating Org1 Identities + cryptogen generate --config=./organizations/cryptogen/crypto-config-org1.yaml --output=organizations org1.example.com + res=0 Creating Org2  Identities + cryptogen generate --config=./organizations/cryptogen/crypto-config-org2.yaml --output=organizations org2.example.com + res=0 Creating Orderer Org Identities + cryptogen generate --config=./organizations/cryptogen/crypto-config-orderer.yaml --output=organizations + res=0 Generating CCP files for Org1 and Org2 Creating network "fabric_test" with the default driver Creating volume "docker_orderer.example.com" with default driver Creating volume "docker_peer0.org1.example.com" with default driver Creating volume "docker_peer0.org2.example.com" with default driver Creating orderer.example.com ... done Creating peer0.org2.example.com ... done Creating peer0.org1.example.com ... done Creating cli ... done CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1d5108ab67ee hyperledger/fabric-tools:latest "/bin/bash" 4 seconds ago Up Less than a second cli 8c806f79310e hyperledger/fabric-peer:latest "peer node start" 13 seconds ago Up 3 Seconds 0.0.0.0:7051 - > 7051 / TCP, : : : 7051 - > 7051 / TCP, 0.0.0.0:17051 - > 17051 / TCP, :::17051->17051/tcp peer0.org1.example.com 1cc1a2786582 hyperledger/fabric-peer:latest "peer node start" 13 seconds ago Up 5 seconds 0.0.0.0:9051->9051/ TCP, :::9051->9051/ TCP, 7051/ TCP, 0.0.0.0:19051->19051/ TCP, :::19051->19051/tcp peer0.org2.example.com 48136ece4636 hyperledger/fabric-orderer:latest "orderer" 13 seconds ago Up 1 Second 0.0.0.0:7050 - > 7050 / TCP, : : : 7050 - > 7050 / TCP, 0.0.0.0:7053 - > 7053 / TCP, : : : 7053 - > 7053 / TCP, 0.0.0.0:17050 - > 17050 / TCP, :::17050->17050/ TCP orderer.example.com c2d41f77ba29 kong:latest "/ docker-entryPoint...." 3 days ago Exited (255) 2 hours ago 0.0.0.0:5555->5555/ TCP, ::5555->5555/ TCP, 0.0.0.0:8000->8000/ TCP, : : : 8000 - > 8000 / TCP, 0.0.0.0:8002 - > 8002 / TCP, : : : 8002 - > 8002 / TCP, 127.0.0.1:8001 - > 8001 / TCP, 0.0.0.0:8443 - > 8443 / TCP, :::8443->8443/ TCP, 127.0.0.1:8444->8444/ TCP kong dc9708005ac9 postgres:9.6 "docker-entrypoint.s... 3 days ago Exited (255) 2 hours ago 0.0.0.0:5432->5432/ TCP, :::5432->5432/ TCP kong-database 746673CA35ef kong-ee "/docker-entrypoint..." 3 days ago Exited (1) 3 days ago kong-ee ed95AAAC394e kicbase/stable:v0.0.27 "/usr/local/bin/entr..." 3 weeks ago Exited (255) 7 days ago 127.0.0.1:55004->22/ TCP, 127.0.0.1:55003->2376/ TCP, 127.0.0.1:55002->5000/ TCP, 127.0.0.1:55001->8443/ TCP, 127.0.0.1:55000->32443/ TCP minikube 6294196025b7 redis "docker-entrypoint-s..." 5 weeks ago Exited (255) 7 days ago 0.0.0.0:6379->6379/ TCP, ::6379->6379/ TCP some-redis 322507528a23 postgres "docker-entrypoint.s..." 5 weeks ago Exited (255) 7 days ago 0.0.0.0:5432->5432/ TCP, :::5432->5432/ TCPCopy the code

Through the output of the script, you can find the entire test environment setup process.

The script will create an Order node, two peer nodes, and a CLI container to interact with other nodes.

However, it does not automatically create channels for us. To automatically create channels for us, you can refer to the help document of network.sh. For example, run the./network.sh createChannel command to create channels

The command output is as follows:

➜ test-network git:(ad8fc2f)./network.sh createChannel Creating channel' mychannel'. If network is not up, starting nodes with CLI timeout of '5' tries and CLI delay of '3' seconds and using database 'leveldb Generating channel  create transaction 'mychannel.tx' + configtxgen -profile TwoOrgsChannel -outputCreateChannelTx /channel-artifacts/ mychannel.tx-channelId myChannel 2021-11-22 11:23:03.380 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration 11:23:03 2021-11-22. 397 CST [. Common tools. Configtxgen. Localconfig] Load - > INFO. 002 Loaded configuration: / Users/zhaojunwei/workspace/hyfa/fabric samples/test - network/configtx/configtx yaml 11:23:03 2021-11-22. 397 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 003 Generating new channel configTX 2021-11-22 11:23:03.402 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 004 Writing new channel tx + res=0 Creating channel mychannel Using organization 1 + peer channel create -o localhost:7050 -c mychannel --ordererTLSHostnameOverride orderer.example.com -f ./channel-artifacts/mychannel.tx --outputBlock ./channel-artifacts/mychannel.block --tls --cafile  /Users/zhaojunwei/workspace/hyfa/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/or derer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem + res=1 + peer channel create -o localhost:7050 -c mychannel  --ordererTLSHostnameOverride orderer.example.com -f ./channel-artifacts/mychannel.tx --outputBlock ./channel-artifacts/mychannel.block --tls --cafile /Users/zhaojunwei/workspace/hyfa/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/ord erer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem + res=1 + peer channel create -o localhost:7050 -c mychannel --ordererTLSHostnameOverride orderer.example.com -f ./channel-artifacts/mychannel.tx --outputBlock ./channel-artifacts/mychannel.block --tls --cafile /Users/zhaojunwei/workspace/hyfa/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/ord erer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem + res=1 + peer channel create -o localhost:7050 -c mychannel --ordererTLSHostnameOverride orderer.example.com -f ./channel-artifacts/mychannel.tx --outputBlock ./channel-artifacts/mychannel.block --tls --cafile /Users/zhaojunwei/workspace/hyfa/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/ord Erer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem + res = 1 2021-11-22 11:23:15. 755 CST [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized Error: got unexpected status: BAD_REQUEST -- channel creation request not allowed because the orderer system channel is not defined Channel creation failedCopy the code

The reason for this error is that since version 2.3, Fabric has supported the creation of application channels without creating system channels, but this is still required in version 2.1

Solutions,

./network.sh down

Stopping network

Stopping cli                    ... done

Stopping peer0.org1.example.com ... done

Stopping peer0.org2.example.com ... done

Stopping orderer.example.com    ... done

Removing cli                    ... done

Removing peer0.org1.example.com ... done

Removing peer0.org2.example.com ... done

Removing orderer.example.com    ... done

Removing network fabric_test

Removing volume docker_orderer.example.com

Removing volume docker_peer0.org1.example.com

Removing volume docker_peer0.org2.example.com

Removing network fabric_test

WARNING: Network fabric_test not found.

Removing volume docker_peer0.org3.example.com

WARNING: Volume docker_peer0.org3.example.com not found.

No containers available for deletion

No images available for deletion

Unable to find image 'busybox:latest' locally

latest: Pulling from library/busybox

e685c5c858e3: Pull complete 

Digest: sha256:e7157b6d7ebbe2cce5eaa8cfe8aa4fa82d173999b9f90a9ec42e57323546c353

Status: Downloaded newer image for busybox:latest
Copy the code

Switch the fabric-samples branch to the specified version and re-perform the up operation

➜  test-network git:(ad8fc2f) ./network.sh up createChannel

Creating channel 'mychannel'.

If network is not up, starting nodes with CLI timeout of '5' tries and CLI delay of '3' seconds and using database 'leveldb with crypto from 'cryptogen'

Bringing up network

LOCAL_VERSION=2.2.4

DOCKER_IMAGE_VERSION=2.2.4

/Users/zhaojunwei/workspace/hyfa/fabric-samples/test-network/../bin/cryptogen

Generating certificates using cryptogen tool

Creating Org1 Identities

+ cryptogen generate --config=./organizations/cryptogen/crypto-config-org1.yaml --output=organizations

org1.example.com

+ res=0

Creating Org2 Identities

+ cryptogen generate --config=./organizations/cryptogen/crypto-config-org2.yaml --output=organizations

org2.example.com

+ res=0

Creating Orderer Org Identities

+ cryptogen generate --config=./organizations/cryptogen/crypto-config-orderer.yaml --output=organizations

+ res=0

Generating CCP files for Org1 and Org2

/Users/zhaojunwei/workspace/hyfa/fabric-samples/test-network/../bin/configtxgen

Generating Orderer Genesis block

+ configtxgen -profile TwoOrgsOrdererGenesis -channelID system-channel -outputBlock ./system-genesis-block/genesis.block

2021-11-22 11:30:32.362 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration

2021-11-22 11:30:32.382 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 002 orderer type: etcdraft

2021-11-22 11:30:32.382 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 Orderer.EtcdRaft.Options unset, setting to tick_interval:"500ms" election_tick:10 heartbeat_tick:1 max_inflight_blocks:5 snapshot_interval_size:16777216 

2021-11-22 11:30:32.382 CST [common.tools.configtxgen.localconfig] Load -> INFO 004 Loaded configuration: /Users/zhaojunwei/workspace/hyfa/fabric-samples/test-network/configtx/configtx.yaml

2021-11-22 11:30:32.384 CST [common.tools.configtxgen] doOutputBlock -> INFO 005 Generating genesis block

2021-11-22 11:30:32.385 CST [common.tools.configtxgen] doOutputBlock -> INFO 006 Writing genesis block

+ res=0

Creating network "fabric_test" with the default driver

Creating volume "docker_orderer.example.com" with default driver

Creating volume "docker_peer0.org1.example.com" with default driver

Creating volume "docker_peer0.org2.example.com" with default driver

Creating peer0.org1.example.com ... done

Creating orderer.example.com    ... done

Creating peer0.org2.example.com ... done

Creating cli                    ... done

CONTAINER ID   IMAGE                               COMMAND                  CREATED          STATUS                     PORTS                                                                                                                                                                                                                            NAMES

1f5b38a37b3c   hyperledger/fabric-tools:latest     "/bin/bash"              2 seconds ago    Up Less than a second                                                                                                                                                                                                                                       cli

ce9abda63afb   hyperledger/fabric-peer:latest      "peer node start"        13 seconds ago   Up 2 seconds               0.0.0.0:9051->9051/tcp, :::9051->9051/tcp, 7051/tcp, 0.0.0.0:19051->19051/tcp, :::19051->19051/tcp                                                                                                                               peer0.org2.example.com

083818ba1bbf   hyperledger/fabric-orderer:latest   "orderer"                13 seconds ago   Up 3 seconds               0.0.0.0:7050->7050/tcp, :::7050->7050/tcp, 0.0.0.0:17050->17050/tcp, :::17050->17050/tcp                                                                                                                                         orderer.example.com

9a03ab178c35   hyperledger/fabric-peer:latest      "peer node start"        13 seconds ago   Up 5 seconds               0.0.0.0:7051->7051/tcp, :::7051->7051/tcp, 0.0.0.0:17051->17051/tcp, :::17051->17051/tcp                                                                                                                                         peer0.org1.example.com

c2d41f77ba29   kong:latest                         "/docker-entrypoint.…"   3 days ago       Exited (255) 2 hours ago   0.0.0.0:5555->5555/tcp, :::5555->5555/tcp, 0.0.0.0:8000->8000/tcp, :::8000->8000/tcp, 0.0.0.0:8002->8002/tcp, :::8002->8002/tcp, 127.0.0.1:8001->8001/tcp, 0.0.0.0:8443->8443/tcp, :::8443->8443/tcp, 127.0.0.1:8444->8444/tcp   kong

dc9708005ac9   postgres:9.6                        "docker-entrypoint.s…"   3 days ago       Exited (255) 2 hours ago   0.0.0.0:5432->5432/tcp, :::5432->5432/tcp                                                                                                                                                                                        kong-database

746673ca35ef   kong-ee                             "/docker-entrypoint.…"   3 days ago       Exited (1) 3 days ago                                                                                                                                                                                                                                       kong-ee

ed95aaac394e   kicbase/stable:v0.0.27              "/usr/local/bin/entr…"   3 weeks ago      Exited (255) 7 days ago    127.0.0.1:55004->22/tcp, 127.0.0.1:55003->2376/tcp, 127.0.0.1:55002->5000/tcp, 127.0.0.1:55001->8443/tcp, 127.0.0.1:55000->32443/tcp                                                                                             minikube

6294196025b7   redis                               "docker-entrypoint.s…"   5 weeks ago      Exited (255) 7 days ago    0.0.0.0:6379->6379/tcp, :::6379->6379/tcp                                                                                                                                                                                        some-redis

322507528a23   postgres                            "docker-entrypoint.s…"   5 weeks ago      Exited (255) 7 days ago    0.0.0.0:5432->5432/tcp, :::5432->5432/tcp                                                                                                                                                                                        mypostgresql

Generating channel create transaction 'mychannel.tx'

+ configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/mychannel.tx -channelID mychannel

2021-11-22 11:30:50.043 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration

2021-11-22 11:30:50.058 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /Users/zhaojunwei/workspace/hyfa/fabric-samples/test-network/configtx/configtx.yaml

2021-11-22 11:30:50.058 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 003 Generating new channel configtx

2021-11-22 11:30:50.061 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 004 Writing new channel tx

+ res=0

Creating channel mychannel

Using organization 1

+ peer channel create -o localhost:7050 -c mychannel --ordererTLSHostnameOverride orderer.example.com -f ./channel-artifacts/mychannel.tx --outputBlock ./channel-artifacts/mychannel.block --tls --cafile /Users/zhaojunwei/workspace/hyfa/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

+ res=0

2021-11-22 11:30:53.152 CST [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized

2021-11-22 11:30:53.196 CST [cli.common] readBlock -> INFO 002 Expect block, but got status: &{SERVICE_UNAVAILABLE}

2021-11-22 11:30:53.201 CST [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized

2021-11-22 11:30:53.405 CST [cli.common] readBlock -> INFO 004 Expect block, but got status: &{SERVICE_UNAVAILABLE}

2021-11-22 11:30:53.412 CST [channelCmd] InitCmdFactory -> INFO 005 Endorser and orderer connections initialized

2021-11-22 11:30:53.621 CST [cli.common] readBlock -> INFO 006 Expect block, but got status: &{SERVICE_UNAVAILABLE}

2021-11-22 11:30:53.628 CST [channelCmd] InitCmdFactory -> INFO 007 Endorser and orderer connections initialized

2021-11-22 11:30:53.831 CST [cli.common] readBlock -> INFO 008 Expect block, but got status: &{SERVICE_UNAVAILABLE}

2021-11-22 11:30:53.837 CST [channelCmd] InitCmdFactory -> INFO 009 Endorser and orderer connections initialized

2021-11-22 11:30:54.046 CST [cli.common] readBlock -> INFO 00a Expect block, but got status: &{SERVICE_UNAVAILABLE}

2021-11-22 11:30:54.052 CST [channelCmd] InitCmdFactory -> INFO 00b Endorser and orderer connections initialized

2021-11-22 11:30:54.264 CST [cli.common] readBlock -> INFO 00c Received block: 0

Channel 'mychannel' created

Joining org1 peer to the channel...

Using organization 1

+ peer channel join -b ./channel-artifacts/mychannel.block

+ res=0

2021-11-22 11:30:57.334 CST [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized

2021-11-22 11:30:57.365 CST [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel

Joining org2 peer to the channel...

Using organization 2

+ peer channel join -b ./channel-artifacts/mychannel.block

+ res=0

2021-11-22 11:31:00.430 CST [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized

2021-11-22 11:31:00.457 CST [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel

Setting anchor peer for org1...

Using organization 1

Fetching channel config for channel mychannel

Using organization 1

Fetching the most recent configuration block for the channel

+ peer channel fetch config config_block.pb -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com -c mychannel --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

2021-11-22 03:31:00.830 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized

2021-11-22 03:31:00.834 UTC [cli.common] readBlock -> INFO 002 Received block: 0

2021-11-22 03:31:00.834 UTC [channelCmd] fetch -> INFO 003 Retrieving last config block: 0

2021-11-22 03:31:00.837 UTC [cli.common] readBlock -> INFO 004 Received block: 0

Decoding config block to JSON and isolating config to Org1MSPconfig.json

+ configtxlator proto_decode --input config_block.pb --type common.Block

+ jq '.data.data[0].payload.data.config'

+ jq '.channel_group.groups.Application.groups.Org1MSP.values += {"AnchorPeers":{"mod_policy": "Admins","value":{"anchor_peers": [{"host": "peer0.org1.example.com","port": 7051}]},"version": "0"}}' Org1MSPconfig.json

Generating anchor peer update transaction for Org1 on channel mychannel

+ configtxlator proto_encode --input Org1MSPconfig.json --type common.Config

+ configtxlator proto_encode --input Org1MSPmodified_config.json --type common.Config

+ configtxlator compute_update --channel_id mychannel --original original_config.pb --updated modified_config.pb

+ configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate

+ jq .

++ cat config_update.json

+ echo '{"payload":{"header":{"channel_header":{"channel_id":"mychannel", "type":2}},"data":{"config_update":{' '"channel_id":' '"mychannel",' '"isolated_data":' '{},' '"read_set":' '{' '"groups":' '{' '"Application":' '{' '"groups":' '{' '"Org1MSP":' '{' '"groups":' '{},' '"mod_policy":' '"",' '"policies":' '{' '"Admins":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Endorsement":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Readers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Writers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '}' '},' '"values":' '{' '"MSP":' '{' '"mod_policy":' '"",' '"value":' null, '"version":' '"0"' '}' '},' '"version":' '"0"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"1"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '},' '"write_set":' '{' '"groups":' '{' '"Application":' '{' '"groups":' '{' '"Org1MSP":' '{' '"groups":' '{},' '"mod_policy":' '"Admins",' '"policies":' '{' '"Admins":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Endorsement":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Readers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Writers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '}' '},' '"values":' '{' '"AnchorPeers":' '{' '"mod_policy":' '"Admins",' '"value":' '{' '"anchor_peers":' '[' '{' '"host":' '"peer0.org1.example.com",' '"port":' 7051 '}' ']' '},' '"version":' '"0"' '},' '"MSP":' '{' '"mod_policy":' '"",' '"value":' null, '"version":' '"0"' '}' '},' '"version":' '"1"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"1"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '}' '}}}}'

+ configtxlator proto_encode --input config_update_in_envelope.json --type common.Envelope

2021-11-22 03:31:01.035 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized

2021-11-22 03:31:01.055 UTC [channelCmd] update -> INFO 002 Successfully submitted channel update

Anchor peer set for org 'Org1MSP' on channel 'mychannel'

Setting anchor peer for org2...

Using organization 2

Fetching channel config for channel mychannel

Using organization 2

Fetching the most recent configuration block for the channel

+ peer channel fetch config config_block.pb -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com -c mychannel --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

2021-11-22 03:31:01.408 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized

2021-11-22 03:31:01.411 UTC [cli.common] readBlock -> INFO 002 Received block: 1

2021-11-22 03:31:01.411 UTC [channelCmd] fetch -> INFO 003 Retrieving last config block: 1

2021-11-22 03:31:01.415 UTC [cli.common] readBlock -> INFO 004 Received block: 1

Decoding config block to JSON and isolating config to Org2MSPconfig.json

+ configtxlator proto_decode --input config_block.pb --type common.Block

+ jq '.data.data[0].payload.data.config'

Generating anchor peer update transaction for Org2 on channel mychannel

+ jq '.channel_group.groups.Application.groups.Org2MSP.values += {"AnchorPeers":{"mod_policy": "Admins","value":{"anchor_peers": [{"host": "peer0.org2.example.com","port": 9051}]},"version": "0"}}' Org2MSPconfig.json

+ configtxlator proto_encode --input Org2MSPconfig.json --type common.Config

+ configtxlator proto_encode --input Org2MSPmodified_config.json --type common.Config

+ configtxlator compute_update --channel_id mychannel --original original_config.pb --updated modified_config.pb

+ configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate

+ jq .

++ cat config_update.json

+ echo '{"payload":{"header":{"channel_header":{"channel_id":"mychannel", "type":2}},"data":{"config_update":{' '"channel_id":' '"mychannel",' '"isolated_data":' '{},' '"read_set":' '{' '"groups":' '{' '"Application":' '{' '"groups":' '{' '"Org2MSP":' '{' '"groups":' '{},' '"mod_policy":' '"",' '"policies":' '{' '"Admins":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Endorsement":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Readers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Writers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '}' '},' '"values":' '{' '"MSP":' '{' '"mod_policy":' '"",' '"value":' null, '"version":' '"0"' '}' '},' '"version":' '"0"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"1"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '},' '"write_set":' '{' '"groups":' '{' '"Application":' '{' '"groups":' '{' '"Org2MSP":' '{' '"groups":' '{},' '"mod_policy":' '"Admins",' '"policies":' '{' '"Admins":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Endorsement":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Readers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Writers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '}' '},' '"values":' '{' '"AnchorPeers":' '{' '"mod_policy":' '"Admins",' '"value":' '{' '"anchor_peers":' '[' '{' '"host":' '"peer0.org2.example.com",' '"port":' 9051 '}' ']' '},' '"version":' '"0"' '},' '"MSP":' '{' '"mod_policy":' '"",' '"value":' null, '"version":' '"0"' '}' '},' '"version":' '"1"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"1"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '}' '}}}}'

+ configtxlator proto_encode --input config_update_in_envelope.json --type common.Envelope

2021-11-22 03:31:01.609 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized

2021-11-22 03:31:01.627 UTC [channelCmd] update -> INFO 002 Successfully submitted channel update

Anchor peer set for org 'Org2MSP' on channel 'mychannel'

Channel 'mychannel' joined

➜  test-network git:(ad8fc2f)
Copy the code

At this point, you can deploy smart contracts. The above is the specific process of building a test environment. If you want to understand the specific operation process of each script in detail, you can dive into the script and see how each step is built.