How to create a backend in NodeJS for Hyperledger Fabric 🤖➡⛓

Start your 2019 journey learning the right skills to become a Blockchain programmer with this tutorial on how to create a backend for Hyperledger Fabric.

Walter Montes
Jan 2 · 6 min read

This is a continuation post from Hyperledger Fabric + Convector + Convector CLI (JavaScript only), in which I show cased how to create a smart contract using Convector (Open source JavaScript Framework).

# Download the source code from github
git clone https://github.com/worldsibu/convector-example-fabcar.git
cd convector-example-fabcar/
# The repo already has a backend so for you to be able to create it from scratch, switch to a branch with not backend
git checkout learning/just-cc
npm i
# Wake yourself up a dev blockchain - run this at any time to destroy and recreate a new blockchain for you!
npm run env:restart
# Now install the chaincode!
npm run cc:start -- car 1
# make sure to be in the root ./convector-example/fabcar
cd packages
npm install generator-express-no-stress-typescript
yo express-no-stress-typescript myapp
# type ENTER a few timescd myapp
npx lerna run compile --scope myapp
npx lerna run dev:debug --scope myapp
If you have this, your backend is running well.
# To send transactions to the blockchain
npx lerna add @worldsibu/convector-adapter-fabric --scope myapp
# To query the couchdb later
npx lerna add @worldsibu/convector-storage-couchdb --scope myapp
npx lerna add fabric-client --scope myapp
npx lerna add fabric-ca-client --scope myapp
npx lerna add @types/bytebuffer --scope myapp
"experimentalDecorators": true,
# now you won't have to replicate the model or the functions (interface) in your backend
npx lerna add car-cc --scope myapp
# Start the backend NodeJs
npx lerna run dev:debug --scope myapp
# Wake yourself up a dev blockchain - run this at any time to destroy and recreate a new blockchain for you!
npm run env:restart
# Now install the chaincode!
npm run cc:start -- car 1
GET localhost:3000/api/v1/examplesGET localhost:3000/api/v1/examples/1POST localhost:3000/api/v1/examples/
Body
{
"make":"Volkswagen",
"model":"Jetta",
"colour":"gray",
"owner":"Walter Montes",
"id":"1"
}

WorldSibu

A unified development platform to create and deploy enterprise smart contract systems.

Walter Montes

Written by

CEO @WorldSibu — https://worldsibu.tech/forma

WorldSibu

WorldSibu

A unified development platform to create and deploy enterprise smart contract systems.