A sample application using hyperledger fabric
This is a sample app created using tuna-app code structure as the basic framework
Prerequisites for Installing Hyperledger Frameworks
- cURL
- Node.js
- npm package manager
- Go Language
- Docker
- Docker Compose
Installation for MacOS
- curl -V
- Check https://nodejs.org/en/download/ for installing Node and NPM
- Installing GO
- cd ~
- sudo curl -O https://storage.googleapis.com/golang/go1.9.2.darwin-amd64.pkg (Check version at https://golang.org/dl/)
- open go1.9.2.darwin-amd64.pkg
- echo $GOPATH
- If nothing comes in the above step, go to .profile(or .bash_profile) and add
- export GOPATH=$HOME/go
- export PATH=$PATH:$GOPATH/bin
- Visit https://www.docker.com/docker-mac to install docker for mac (Installing docker for mac or docker toolbox will also download docker-compose)
Installing hyperledger Fabric
- curl -sSL https://goo.gl/Q3YRTi | bash (Check Check https://hyperledger-fabric.readthedocs.io/en/latest/samples.html#binaries for latest URL)
- docker images
- If the images are not in latest tag run docker tag hyperledger/fabric-tools:x86_64-1.0.2 hyperledger/fabric-tools:latest (Replace fabric-tools:x86_64-1.0.2 accordingly)
- export PATH=$PWD/bin:$PATH
Installing hyperledger Fabric Sample Code
Getting started with the network
- cd fabric-samples/first-network
- ./byfn.sh -m generate
- It generates all the certificates, keys and Genesis block required for network configuration
- ./byfn.sh -m up
- It starts the network
- ./byfn.sh -m down
- It shuts down the network
Writing a sample application
- Download the education repository
- git clone https://github.com/hyperledger/education.git
- cd education/LFS171x/fabric-material/tuna-app
- docker rm -f $(docker ps -aq) (To remove pre-existing containers)
- ./startFabric.sh (To start the network)
- npm install (To install required packages from package.json file)
- node registerAdmin.js (Register the admin)
- node registerUser.js (Register the user)
- node server.js (Start the application)
- open localhost:8000 and your app would be running
Deploying the modified codechain
- Move your chaincode (i.e. invoice-chaincode.go) to /opt/gopath/src/github.com/invoice-app (Check the name in startFabric.sh and accordingly replace invoice-app)
- If the above directory is not present, then create the directoty and move
- Troubleshooting
- If node registerUser.js gives error, run rm -rf .hfc-key-store/ and then run the command for both admin and user in order.