Chaincode development environment

Every consortium member should follow the instructions on this page.

Open a Cloud9 terminal and paste the following commands to setup a NodeJS development environment.

curl -o- | bash
add_line_to_profile_if_not_there() { grep -qxF "$1" .bash_profile || echo "$1" >> .bash_profile; }
export line="export NVM_DIR=\"$HOME/.nvm\""
add_line_to_profile_if_not_there "$line"
export line="[ -s \"$NVM_DIR/\" ] && \. \"$NVM_DIR/\""
add_line_to_profile_if_not_there "$line"
. .bash_profile
nvm install lts/carbon
mkdir ~/environment/chaincode
touch ~/environment/chaincode/package.json
touch ~/environment/chaincode/products.js
touch ~/environment/chaincode/products_test.js

These commands also create a new folder for you in the Cloud9 IDE called chaincode, where you will be placing your source code. You will be editing your chaincode in the Cloud9 IDE. Open that folder and replace the contents of package.json with the following code.

  "name": "chaincode",
  "version": "1.0.0",
  "scripts": {
    "test": "mocha *_test.js",
    "start": "node products.js"
  "dependencies": {
    "fabric-shim": "^1.2.4"
  "devDependencies": {
    "@theledger/fabric-mock-stub": "^2.0.3",
    "chai": "^4.2.0",
    "chai-as-promised": "^7.1.1",
    "chai-datetime": "^1.6.0",
    "moment": "^2.25.3"

Save the file, then execute the following commands from the Cloud9 terminal to install chaincode dependencies.

nvm use lts/carbon
mkdir -p ~/environment/chaincode
cd ~/environment/chaincode
npm install mocha@7.2.0 -g
npm install browserify@16.5.1 -g
npm install
npm install javascript-state-machine@3.1.0
npm install loglevel@1.6.8
browserify node_modules/javascript-state-machine --standalone state-machine > state-machine.js
browserify node_modules/loglevel --standalone loglevel > loglevel.js