Skip to content

Latest commit

 

History

History
152 lines (104 loc) · 6.03 KB

env_setup.md

File metadata and controls

152 lines (104 loc) · 6.03 KB

Chaincode Development Environment

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).

1. Git

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.

Verify Git Installation

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

2. GoLang

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+.

Verify Go Installation

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.

3. Node.js

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.

Verify Node.js Installation

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.

4. Hyperledger Fabric

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.

Continue the Fabric Install Instructions

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.

  1. Create the parent directories on your GOPATH

    mkdir -p $GOPATH/src/github.com/hyperledger
    cd $GOPATH/src/github.com/hyperledger
    
  2. Clone the appropriate release codebase into $GOPATH/src/github.com/hyperledger/fabric

    git clone https://github.com/hyperledger/fabric.git
    
  3. Match this version to the commit hash of your network/Fabric (the first 7 characters will work)

    cd fabric
    git checkout ae4e37d
    
  4. Confirm the level using git branch. It should show the commit level matching the one you provided.

    git branch
    

Verify Fabric Installation

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.

5. IDE Suggestions

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.

6. Finish Up

Now that everything is setup, head back to the tutorial.