This is a blockchain-based client application to fight against the medicines black market. To read our report follow this link
- 🛠 Forging the fabric network
- 🎬 Part 1: before we start
- 🏎 Part 2: Starting up the engine
- ✍🏼 Part 3: OAuth2.0 configuaration
- 📦 Part 4: Install dependencies
- 👽 Part 5: Adding the first user to the wallet
- 🔮 Part 6: See the magic work
- 📧 Part 7: Use the API to interact with the blockchain
- 🪪 License
To make the private blockchain work we need a local Fabric network to test on. We'll start right away but before that can happen you need to clone the repository on your machine.
Clone this repo with git, if you don't have git installed use the following commands first.
sudo apt update
sudo apt install git
Check if the installation succeeded.
git --version
Example output: git version 2.17.1
If all this is correct, we can clone the application repo with the following command.
git clone https://github.com/DeefDeMeef/medicine-blockchain-ledger.git
To work with the Fabric Network we also need their repo. clone this repo with the following comment.
git clone https://github.com/hyperledger/fabric-samples.git
The last part we need for a succesfull installation is Docker. Follow this link to download it from their website.
This repo contains 3 folders with the following components of the ledger.
- Chaincode: the logic of the blockchain network.
- Client/backend: a backend application (REST API) that allows users to interact with the blockchain network.
- Client/frontend: An Angular application that interacts with the backend.
In this step we will start the blockchain network. Make sure you execute the following commands correctly.
First go to the fabric-samples
folder that we cloned in part 1 of the installation and go into the
fabric-samples/test-network
folder.
Execute the following command to setup a network:
./network.sh up createChannel -ca -s couchdb
If you want to stop this network at any time simply use this command:
./network.sh down
A chaincode is a container to deploy code on the Hyperledger Fabric blockchain network. This must be done in the
fabric-samples/test-network
folder.
./network.sh deployCC -ccn medicine-tracking -ccp [base-folder]/medicine-blockchain-ledger/chaincode -ccv 1 -ccs 1 -ccl javascript
Where [base-folder] is the location where you cloned the repositories, medicine-tracking is the name of the chaincode, the parameter -ccl javascript is the language used to write the chaincode. The parameter -ccv 1 and -ccs 1 refers to the version and sequence. If you change something in your chaincode and wants to redeploy, you should increment these values.
For this part you need a Google account.
- Open the Google APIs & Services Console
- To access the OAuth2.0 feature, you should create a project. You can click the "create project" button to inform your project details
- Go to Credentials
- Select Create Credentials > OAuth Client ID. To use this feature, you should configure a consent screen. You can choose for an external account, and fill basic information such as the application name, and contact information.
- Select Web Application
- Give a name to the Web Application
- Inform http://localhost:4200 in Authorised JavaScript origins field
- Inform http://localhost:4200/auth/google/callback in the Authorised redirect URIs field
- A new configuration will be created and shown in the table
- Select the download option of the newly created config. A JSON file will be generated
- Move this file to the /client/backend/src/auth folder with the name oauth2.keys.json
Using the terminal window, execute the following command in the client/backend folder:
npm --logevel=error install
Do the same command in the client/frontend folder. This should install all the required dependencies in node_modules.
The administrator of an organisation can issue certificates to new users. You will need that to create the participants of the medicine tracking network such as doctors, pharmacies and ofcourse patients. Thus, you should export the admin certificate to the client/backend/wallet folder. To do so, execute the following operation:
node src/enrollAdmin.js
This command logs in to the certificate authority of organisation 1 and download the certificate of the administrator of org1, and add it to the wallet folder.
Note: If you run this command again, you should manually remove the previous certificate file of the admin user(admin.id). Otherwise, the system will generate an error message telling that the certificate already exists.
Now you are ready to run the actual application. To do so run the following command in client/backend:
npm start
Expected output:
> [email protected] start
> ./node_modules/nodemon/bin/nodemon.js src/app.js
[nodemon] 2.0.18
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node src/app.js`
listening on port 8080
Done connecting to network.
You should install Angular first. If you do not have it yet, run the following command in your terminal:
npm install -g @angular/cli
To run the application, you should first install dependencies if you didn't do it yet in the root folder of the front-end application.
npm --logevel=error install
Then, you can start a local server, by running this command in the root folder of the front-end application.
ng serve
After start-up you can access the application from http://localhost:4200.
After login the home page will show the generated Json Web Token from Google. It should be used in the postman calls.
If everything is running correctly and installed as explained then we should be able to make requests to the server to interact with the blockchain. Dont forget to give the auth token with every request you do.
A handy tool to make these request is Postman You can import the requests by the following link in Postman
https://www.getpostman.com/collections/7498393f09417a317def
Creating prescription
POST http://localhost:8080/rest/prescription
{
"timestamp": "11/07/2022",
"medicineId": "TEST",
"quantity": "10",
"expiration": "12/07/2022",
"patientId": "[email protected]",
"doctorId": "[email protected]",
"hospitalId": "WKZ"
}
Getting prescriptions
GET http://localhost:8080/rest/participants/[email protected]/prescriptions
{}
Getting prescriptions
PUT http://localhost:8080/rest/prescription/:prescriptionId/pickedup
{
"participantId": "[email protected]"
}