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:
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:
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.