This repository contains chaincode, test-network and API made to work as a backend for examination system project whose frontend can be found here.
Currently, the file structure is same as fabric-samples provided by hyperledger.
- The chaincode is written with reference of fabcar example.
- APIs are written in Node.js.
- And for network test-network is being used.
Make sure that you have setup your environment and are done with all the prerequisites.
Versions:
- fabric: 2.1.0
- golang: go1.14.1
- node: v10.15.2
- npm: 5.8.0
Now, just run the following command to clone and pull all the binaries and dockers images. No need to clone this repository manually, it'll all be done by the script.
curl -sSL https://bit.ly/3eh7nxE | bashAfter running this you will have to start the network and deploy the chaincode on it. For that just
cd exam_result
sudo ./startNetwork.shNow, enroll admin and register user by doing
cd javascript
node enrollAdmin.js
node registerUser.jsIf everything goes as expected the chaincode will be deployed on channel mychannel and fabric network will be up and running.
Now heading towards the API, run
node app.jswhich will start a node server on localhost:8080.
-
There are 2 apis namely
getResultwhich will fetch result from the fabric ledger, it needsemailIdas a query param of the candidate who has already taken the exam/test. Check request and response formats. This API callsqueryResultchaincode function. -
Other one is
sendResultwhich takes the request in JSON, calculates result and pushes it to the blockchain. Check the request and response. This API callscreateResultwith appropriate args.
- For now tis just has 3 basic functions as
initLedgerwhich initializes the ledger with some dummy values as soon as chaincode is deployed. - Then there's
queryResultwhich uses 'emailId' as an argument to pull state/data from the ledger. - Finally
createResultis used to insert result in the blockchain.

