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 | bash
After running this you will have to start the network and deploy the chaincode on it. For that just
cd exam_result
sudo ./startNetwork.sh
Now, enroll admin and register user by doing
cd javascript
node enrollAdmin.js
node registerUser.js
If 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.js
which will start a node server on localhost:8080
.
-
There are 2 apis namely
getResult
which will fetch result from the fabric ledger, it needsemailId
as a query param of the candidate who has already taken the exam/test. Check request and response formats. This API callsqueryResult
chaincode function. -
Other one is
sendResult
which takes the request in JSON, calculates result and pushes it to the blockchain. Check the request and response. This API callscreateResult
with appropriate args.
- For now tis just has 3 basic functions as
initLedger
which initializes the ledger with some dummy values as soon as chaincode is deployed. - Then there's
queryResult
which uses 'emailId' as an argument to pull state/data from the ledger. - Finally
createResult
is used to insert result in the blockchain.