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
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
.
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.
Next verify you can build GoLang code with the hello world example.
Download and install the latest Node.js LTS version.
Open a command prompt/terminal and make sure the following commands work on your machine:
$ node -v
v6.10.1
$ npm -v
3.10.10
Any chaincode that you write will need to import the chaincode shim from Hyperledger Fabric.
Therefore in order to compile chaincode locally you will need to have the fabric code present in your GOPATH
.
Choose 1 option below:
-
Option 1: 🍭 I don't want to modify chaincode - If you only want to run marbles cc as is, you can skip this step completely. Head back to the tutorial.
-
Option 2: I want to modify chaincode and use a local Fabric network
- You are going to use the master branch of the Hyperledger fabric.
- Remember this hash
14055d7
and go to theContinue the Fabric Install Instructions
section below. You will enter the hash there.
-
Option 3: I want to modify chaincode and use the Blockchain Service for my network
-
You are most likely going to need to use the v1.0.0-preview Hyperledger fabric version. If you have a network, then the exact Fabric version can be found in the Release Notes section of your network's UI.
-
Get the hash from your network or use the hash
14055d7
. Go to theContinue the Fabric Install Instructions
section below. You will enter the hash there. -
Update 5/1/2017 If you are on Windows and using the Blockchain Sevice, please use this commit hash instead:
0616a9ddc02cc541409c9d77c8b7e97523a8b96e
. Windows needs a Fabric fix that disables pkcs11 that was not avaible until April 1st, 2017 (no joking). Other OSes should be able to use the same version in their release note.
-
The release you are cloning locally should match the Hyperledger Fabric network you are using when you deploy your application.
You should apply the choice you made above to the instructions below when doing the git checkout
step.
-
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
git clone https://github.com/hyperledger/fabric.git
-
Match this version to the commit level of your network (1st 7 characters will work)
cd fabric git checkout 14055d7
-
Confirm the level using git branch. It should show the commit level matching the one you provided.
git branch
Open a command prompt/terminal and browse to this directory $GOPATH/src/github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
$ go build -tags nopkcs11 .
It should return with no errors/warnings.
Visual Studio Code is a free IDE that supports all the languages in Marbles such as JS/CSS/HTML/GoLang.
Like VS Code, Atom has plugins to support any of the languages needed to develop chaincode or modify our examples.
Now that everything is setup, head back to the tutorial.