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

Getting ready

Let's first get the fabric library in our environment. Navigate to the assetmgr directory, run the get chaincode library command, and then start build:

cd $GOPATH/src/assetmgr
go get -u github.com/hyperledger/fabric/core/chaincode/shim
go build

This will load the chaincode library and compile the Go code. Next, we will deploy the chaincode using the dev mode. Normally, we need to define our own channel, peer, and configuration Docker container to run our chaincode. Hyperledger, however, provides a sample dev network with a pre-generated orderer and channel artifact. This allows the user to start using chaincode for quick development and testing. You should have already set up the Fabric runtime environment with the fabric-samples project. If you haven't already done so, check out the previous chapter, or refer to fabric-samples in the GitHub link and follow the instructions: https://github.com/hyperledger/fabric-samples.

At the time of writing this book, 1.4 is the latest version of fabric-samples.

In our example project, we use the build in the fabric-samples project and set this same project as the default user home directory, as follows:

Let's now open three Terminals and navigate to the chaincode-docker-devmode directory of fabric-samples:

$ cd chaincode-docker-devmode