- Hyperledger Cookbook
- Xun (Brian) Wu Chuanfeng Zhang Andrew Zhang
- 341字
- 2021-06-24 14:59:43
Creating and executing startFabric.sh
Follow these steps:
- Navigate to the itasset folder
- Create a Client folder
- Under the Client folder, create a script file called startFabric.sh
- Create a folder called webapp
Here is the folder structure we have created so far:

The startFabric.sh file contains the following commands:
export MSYS_NO_PATHCONV=1
starttime=$(date +%s)
CC_RUNTIME_LANGUAGE=golang
CC_SRC_PATH=github.com/assetmgr
# clean the keystore
rm -rf ./hfc-key-store
# launch network; create a channel and join peer to the channel
cd /home/ubuntu/fabric-samples/basic-network
./start.sh
The script calls the start.sh file in the fabric-samples section of the basic-network project to bring up the Fabric network. This will start the orderer, couchdb, cli, peer, and ca container. Then, we issue the cli command to install and instantiate our assetmgr chaincode:
# bring up cli cntainer to install, instantiate, invoke chaincode
docker-compose -f ./docker-compose.yml up -d cli
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode install -n assetmgr -v 1.0 -p "$CC_SRC_PATH" -l "$CC_RUNTIME_LANGUAGE"
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -n assetmgr -l "$CC_RUNTIME_LANGUAGE" -v 1.0 -c '{"Args":["100","ipad", "0e83ff"]}' -P "OR ('Org1MSP.member','Org2MSP.member')"
After that, we set up our chaincode in a basic network environment. In the next step, we invoke our chaincode from cli:
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode invoke -o orderer.example.com:7050 -C mychannel -n assetmgr -c '{"Args":["Order", "100", "initial order from school", "New York"]}'
Once the script file is created, it is ready to execute the script. First, we should make sure there aren't any other Docker containers still running. Here are the commands to clean up the Docker environment:
~/fabric-samples/first-network$ ./byfn.sh down
~/fabric-samples/first-network$ docker rm -f $(docker ps -aq)
~/fabric-samples/first-network$ docker network prune
Now, we can run the script.sh file:
~/itasset/client$ ./startFabric.sh
Here is the result after executing the script.sh file:

As we can see from the result, the Fabric CA, client, peer, orderer, and counchdb containers are running. The assetmgr chaincode is installed and instantiated in the blockchain. After executing the invoke order chaincode command, the orgAsset status is changed to ORDER.
- 普林斯頓微積分讀本(修訂版)
- 西去東來:沿絲綢之路數(shù)學知識的傳播與交流
- Hands-On Blockchain Development in 7 Days
- 圖解博弈論
- 世界是隨機的:大數(shù)據(jù)時代的概率統(tǒng)計學
- 妙趣橫生博弈論:事業(yè)與人生的成功之道(白金版)
- 一個數(shù)學家的辯白(雙語版)
- 怎樣解題:數(shù)學競賽攻關(guān)寶典(第3版)
- 丈量世界:時間、空間與數(shù)學(萬物皆數(shù)學)
- 特殊函數(shù)概論習題解答
- 基于變分法的細胞演化建模
- 代數(shù)的歷史:人類對未知量的不舍追蹤(修訂版)
- 模糊數(shù)學基礎(chǔ)及應用
- 說不盡的圓周率
- Radioss 基礎(chǔ)理論與工程高級應用