HyperLeger

Introduction

An instruction for setting up HyperLedger in development mode.

This guide is intended for Windows (10). However, Mac and Linux can also follow the basic principles.

Setup Instruction

  1. Download and install Git at https://git-scm.com/downloads
  2. Install Go Lang
    1. Download and install Go at https://golang.org/
    2. Add Environment variables (System variables)
      1. GOROOT = C:\Go\
      2. GOPATH = C:\GoProjects\
  3. Download and install Gradle
    1. Download https://services.gradle.org/distributions/gradle-3.4-bin.zip
    2. Extract and copy to C:\
    3. Add C:\gradle-3.4\bin to PATH (Environment Variables)
  4. Download and install Vagrant at https://www.vagrantup.com/downloads.html
  5. Download and install VirtualBox at https://www.virtualbox.org/wiki/Downloads
  6. Launch Git Bash (the terminal)
    1. git config --global core.autocrlf false
    2. cd $GOPATH
    3. mkdir src
    4. cd src
    5. mkdir -p github.com/hyperledger
    6. git clone https://github.com/hyperledger/fabric.git
    7. git checkout v0.6 (we only use version 0.6 of fabric now)

Launch Development Environment

Typically, to develop and test chaincode, we need at least 3 terminals opened to:

  • Run the peer node(s)
  • Run the chaincode (e.g. fabric/examples/chaincode/java/SimpleSample, you should replace with your corresponding chaincode folder)
  • Send the query

Below are steps to launch, deploy and test chaincode:

Run the peer node(s)

  1. Launch Git Bash (the terminal)
    1. cd $GOPATH/src/github.com/hyperledger/fabric/devenv
    2. vagrant.exe up
    3. vagrant.exe ssh
  2. Now we should be in the terminal of the virtual machine
    1. cd $GOPATH/src/github.com/hyperledger/fabric
    2. make peer
    3. peer node start --peer-chaincodedev

Run the chaincode

  1. Launch another Git Bash
    1. cd $GOPATH/src/github.com/hyperledger/fabric/devenv
    2. vagrant.exe ssh
  2. Now we should be in the terminal of the virtual machine (2nd terminal)
    1. Do this only once (the first time)
      1. cd $GOPATH/src/github.com/hyperledger/fabric/core/chaincode/shim/java
      2. gradle -b build.gradle clean
      3. gradle -b build.gradle build
    2. Do this when we need to build the chaincode
      1. cd $GOPATH/src/github.com/hyperledger/fabric/... (to the chaincode folder, e.g. fabric/examples/chaincode/java/SimpleSample)
      2. gradle build
    3. Do this every time to run the chaincode
      1. cd $GOPATH/src/github.com/hyperledger/fabric/... (to the chaincode folder, e.g. fabric/examples/chaincode/java/SimpleSample)
      2. gradle run

Send query to chaincode

  1. Launch another Git Bash
    1. cd $GOPATH/src/github.com/hyperledger/fabric/devenv
    2. vagrant.exe ssh
  2. Now we should be in the terminal of the virtual machine (3rd terminal)
    1. cd $GOPATH/src/github.com/hyperledger/fabric/devenv
    2. Here we can deploy, query, etc. the chaincode

Develop with IntelliJ IDEA

You can develop chaincode (java) with IntelliJ IDEA. It is simple and straightforward.

  1. Download and install IntelliJ IDEA at https://www.jetbrains.com/idea/. If you are a student, the educational pack of JetBrains offers the ultimate version. To do so, register with a student email then activate the offer. Otherwise you can use the community version or purchase the ultimate license.
  2. Open the project with the root at the chaincode folder (e.g. fabric/examples/chaincode/java/SimpleSample).
  3. Setup the project SDK (java 1.8, typically at C:\Program Files\Java\jdk)
  4. Add the jar for Gradle: org.hyperledger:shim-client:1.0 ($GOPATH\src\github.com\hyperledger\fabric\core\chaincode\shim\java\build\libs\shim-client-1.0.jar )
  5. And now every errors are resolved and HAPPY CODING!!!