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 Node.js v6.2.0 - v6.11.1. As of 1/4/2018 Marbles has dependencies that will not work with node.js v7 or v8.
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
.
If you don't do this step you run the risk of being unable to build your chaincode locally.
Choose 1 option below (read each before you choose):
-
Option 1: 🍭 This option is for those that do not want to modify chaincode. You will be running marbles as is.
- There are no steps, you are already done! Head back to the tutorial.
-
Option 2: This option is for those that want to modify chaincode and use a local Fabric network with the most recent Fabric version
- Releases of Hyperledger Fabric.
- You will need to find the commit hash of your release. Click the releases link above and find the most recent release. Click it and the release's commit hash is below the release version, similar to the picture below.
- Remember this hash and go to the
Continue the Fabric Install Instructions
section below. You will enter the hash there.
-
Option 3: Choose this option if you want to modify chaincode and use the Blockchain Service for my network
- Get the commit hash from your network or use the hash
ae4e37d
.- If you have a network on the Bluemix service, then the exact Fabric version can be found in the "Support" tab under the "Release Notes" section of your network's dashboard.
- Go to the
Continue the Fabric Install Instructions
section below. You will enter the hash there.
- Get the commit hash from your network or use the hash
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.
The point of all of this is to simply have the same version of Fabric on your local computer as the one running your network.
-
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 hash of your network/Fabric (the first 7 characters will work)
cd fabric git checkout ae4e37d
-
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. You should also see that an executable was created in this directory.
Note that the nopkcs11
tag is important.
PKCS 11 is a Public-Key Cryptography Standard that you are unlikely to have on your system.
Remember to use this flag as you develop/build your chaincode.
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.