The following is a list of dependencies and recommended tools that you should install in order to develop chaincode. These dependencies are not optional (unless specifically stated).
Git is a wildy popular version control tool for software development.
We can use it for chaincode development and our application development.
It is required part of this demo since we will use git clone
to download Marbles and Hyperledger Fabric code.
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 needed 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 peer.
At time of writing, this chaincode is known to build successfully with version 1.9.0+
.
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.9.2 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 Go's hello world example.
Download and install Node.js v6, or v8. These are the only supported/compatible versions. As of 8/28/2018 Marbles has dependencies that will not work with node.js v9 or v10.
Open a command prompt/terminal and make sure the following commands work on your machine:
$ node -v
v8.11.4
$ npm -v
5.6.0
It is not important that your version numbers match the ones shown above. It is important that the commands printed out compatible verison numbers.
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 will not be able to build your chaincode locally, which means you will be unable to make modifications.
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 IBM Cloud 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 marbles.
Now that everything is setup, head back to the tutorial.