Hyperledger Cookbook
上QQ阅读APP看书,第一时间看更新

Building and deploying the chaincode

  1. Open Terminal two. This Terminal will build and deploy the chaincode. Since we write and build the chaincode from our local Unix system, the chaincode is not yet in the Docker containers. Run the following command in the chaincode-docker-devmode folder:
docker exec -it chaincode bash

  1. The output will be a list of folders:
abac chaincode_example02 fabcar marbles02 marbles02_private sacc
  1. Let's create an assetmgr folder:
mkdir assetmgr

This will create an assetmgr folder in the Fabric container. First, type exit. This will exit the container and return to the chaincode-docker-devmode folder. Check the Fabric chaincode container ID by typing docker ps. You will get a similar result to the following:

In our example, the chaincode container ID is dbf9a0a1da76. The peer port is 7051.

  1. With the container ID, we can copy the local chaincode to the chaincode container. Run the following command:
docker cp ~/itasset/src/assetmgr/assetmgr.go dbf9a0a1da76:/opt/gopath/src/chaincode/assetmgr
  1. Launch the chaincode container again:
docker exec -it chaincode bash
  1. Navigate to the assetmgr folder and execute the go build command. This will compile our assermgr.go in the chaincode container, as shown in the following screenshot: 

The assetmgr chaincode can be found at the following path: /opt/gopath/src/chaincode/assetmgr.

  1. Run the chaincode by providing the peer address and chaincode ID name. The command is as follows:
CORE_PEER_ADDRESS=peer:7052 CORE_CHAINCODE_ID_NAME=mycc:0 ./assetmgr
  1. This command will deploy the chaincode to the peer node at 7052. If you don't see any errors, the chaincode will start with peer. The log indicates that assetmgr.go successfully registered with peer: