MediChain is a blockchain-powered drug authenticity verification system that helps combat counterfeit medicines using Ethereum blockchain technology.
MediChain allows patients and pharmacies to verify medicines through a unique QR code printed on each package. The system uses smart contracts to track each drug's information and verification history.
- QR Code Verification: Scan medicine QR codes to instantly verify authenticity
- Blockchain Security: All drug data is stored securely on the blockchain
- Counterfeit Detection: Alert system identifies suspicious verification patterns
- Trustless Verification: No need to trust a central authority
This guide helps you set up MediChain locally without requiring any external blockchain providers or wallets.
- Node.js (v14 or later)
- npm or yarn
# Clone the repository
git clone https://github.com/HWKDS/MediChain.git
cd MediChain
# Install project dependencies
npm install
# Install Ganache for local blockchain
npm install -g ganacheTHEREUM_NETWORK=local
PORT=5000
# Contract address (will be filled automatically by deploy_local.js)
CONTRACT_ADDRESS=
- Start a local blockchain using Ganache:
# Run Ganache with deterministic addresses
ganache --deterministic- In a new terminal, compile and deploy the smart contract:
# Compile the contracts
npx truffle compile
# Deploy using the local script
node scripts/deploy_local.jsThe deployment script will:
- Deploy the MediChain contract to your local blockchain
- Register a test manufacturer
- Add a test drug with QR code "MED-12345"
- Update the
.envfiles with the contract address
cd medichain-backend
# Install dependencies (if not done already)
npm install
# Start the server
node server.jsThe server will connect to the local blockchain and use the first Ganache account for transactions.
cd medichain-frontend
# Install dependencies (if not done already)
npm install
# Start the development server
npm startThe application should open in your browser at http://localhost:3000
-
Verify the test drug:
- Enter "MED-12345" in the verification field, or
- Generate a QR code with text "MED-12345" and scan it using the app's scanner
-
Register additional drugs using the API:
curl -X POST http://localhost:5000/api/register \
-H "Content-Type: application/json" \
-d '{
"qrCode": "MED-67890",
"name": "AnotherDrug",
"manufacturer": "OtherPharma",
"batchNumber": "BATCH002",
"manufactureDate": "2023-01-01",
"expiryDate": "2025-01-01",
"ingredients": "Active ingredients, excipients"
}'MediChain consists of three main components:
- Smart Contract: Stores drug information and handles verification logic
- Backend API: Acts as a bridge between the frontend and blockchain
- Frontend UI: User interface for scanning QR codes and displaying verification results
-
"Cannot read properties of undefined" errors:
- Ensure Ganache is running with
--deterministicflag - Check that the contract address in
.envfiles matches the deployed contract
- Ensure Ganache is running with
-
Transaction reverted errors:
- Increase gas limit for complex transactions (usually 500,000 is sufficient)
- Make sure you're using the authorized manufacturer account
-
QR scanner not working:
- Ensure you've granted camera permissions
- Use a well-lit QR code
- Try entering the code manually if scanning fails
If you encounter persistent issues, try these steps:
-
Restart Ganache with a clean state:
ganache --deterministic --clear
-
Redeploy the contract:
node scripts/deploy_local.js
-
Restart the backend and frontend servers
/contracts: Solidity smart contracts/migrations: Truffle migration scripts/medichain-frontend: React frontend application/medichain-backend: Express.js backend API/scripts: Deployment and utility scripts
- Mobile application for easier verification
- Integration with pharmaceutical supply chain systems
- Multi-factor authentication for manufacturers
- Analytics dashboard for monitoring drug verifications