The following is a list of dependencies and recommended tools that you should install in order to develop chaincode.
Git is a great version control tool to familiarize yourself with, both for chaincode development and software development in general. Also, git bash, which is installed with git on Windows, is an excellent alternative to the the Windows command prompt.
After following the installation instructions above, you can verify that git is installed using the following command:
$ git --version
git version 2.11.1.windows.1
Once you have git installed, go create an account for yourself on GitHub. The IBM Blockchain service on Bluemix currently requires that chaincode be in a GitHub repository in order to be deployed through the REST API.
Currently, Go is the only supported language for writing chaincode. The Go installation installs a set of Go CLI tools which are very useful when writing chaincode. For example, the go build
command allows you to check that your chaincode actually compiles before you attempt to deploy it to a network. At time of writing, this chaincode is known to build successfully with version 1.7.5.
Follow the installation instructions linked above. You can verify that Go is installed properly by running the following commands. Of course, the output of go version
may change depending on your operating system.
$ go version
go version go1.7.5 windows/amd64
$ echo $GOPATH
C:\gopath
Your GOPATH
does not need to match the one above. It only matters that you have this variable set to a valid directory on your filesystem. The installation instructions linked above will take you through the setup of this environment variable. Why is this variable important? When you run go build
to test that your chaincode compiles, Go is going to look in the $GOPATH/src
directory for the non-standard dependencies that you list in the import
block of your chaincode.
- v0.5-developer-preview Hyperledger fabric
- v0.6-preview Hyperledger fabric
- master branch of the Hyperledger fabric
Any piece of chaincode that you write will need to import the chaincode shim from Hyperledger fabric in order to be able to read and write data to/from the ledger. In order to compile chaincode locally, which you will be doing a lot, you will need to have the fabric code present in your GOPATH
.
Three different releases of the fabric are linked above. The release you choose needs to match the Hyperledger network you are deploying your chaincode onto. You will need to make sure that the fabric release you choose is stored under $GOPATH/src/hyperledger/fabric
.
The instructions below should take you through the process of properly installing the v0.5 release on your GOPATH
.
# Create the parent directories on your GOPATH
mkdir -p $GOPATH/src/github.com/hyperledger
cd $GOPATH/src/github.com/hyperledger
# Clone the appropriate release codebase into $GOPATH/src/github.com/hyperledger/fabric
# Note that the v0.5 release is a branch of the repository. It is defined below after the -b argument
git clone -b v0.5-developer-preview https://github.com/hyperledger-archives/fabric.git
If you are installing the v0.6 release, use this for your git clone
command:
# The v0.6 release exists as a branch inside the Gerrit fabric repository
git clone -b v0.6 http://gerrit.hyperledger.org/r/fabric
If the fabric is not installed properly on your GOPATH
, you will see errors like the one below when building your chaincode:
$ go build .
chaincode_example02.go:27:2: cannot find package "github.com/hyperledger/fabric/core/chaincode/shim" in any of:
C:\Go\src\github.com\hyperledger\fabric\core\chaincode\shim (from $GOROOT)
C:\gopath\src\github.com\hyperledger\fabric\core\chaincode\shim (from $GOPATH)
A list of known specific releases is included below:
- Blockchain service on Bluemix - use the v0.6 release
Postman is a REST API testing tool. Though it is deprecated, we still use the REST API in the fabric for this tutorial because it allows you to deploy and test your chaincode without needing to use the fabric SDK. You'll learn more about the fabric SDK in our other examples.
Download the Postman tool. Depending on your operating system, you may also need to install Chrome to use Postman. Once you have the tool running, import the request collection included in this repository. This collection contains requests for enrolling a user on a peer, as well as deploying, invoking, and querying chaincode. The collection repository contains all the REST calls need to complete this tutorial.
Node.js is NOT necessary to develop chaincode, but most of our demos are built on Node.js, so it might be handy to go ahead and install it now. Also, you'll need it when you start using the fabric SDK.
Download the latest Node.js LTS installation package and make sure the following commands work on your machine:
$ node -v
v6.10.1
$ npm -v
3.10.10
Visual Studio Code is a free IDE that supports both Node.js and Go through plugins. All of our demos and examples use either one or both of these languages. It also has tab support, git integration, and debugging support.
Like VS Code, Atom has plugins to support any of the languages needed to develop chaincode or modify our examples.