This is the backend API for MedChain Vault – a secure, blockchain-powered platform for uploading, verifying, and managing Electronic Medical Records (EMRs) with on-chain access control.
- Secure File Upload: Receives EMRs, hashes files, uploads to IPFS, and logs file info to the smart contract.
- On-chain Audit Trail: Fetches all upload events for transparent history.
- Access Control: Lets file owners grant or revoke access to files for specific users (wallet addresses).
- Verification: Allows anyone with permission to verify a file’s authenticity and integrity.
- Node.js (Express.js)
- Ethers.js (for smart contract interaction)
- Pinata (IPFS file storage)
- Multer (handling file uploads)
- dotenv (environment variables)
npm installCreate a .env file in /backend with these variables:
CONTRACT_ADDRESS=0xYourContractAddress
PRIVATE_KEY=your_private_key
RPC_URL=https://your_rpc_url
PINATA_API_KEY=your_pinata_api_key
PINATA_API_SECRET=your_pinata_api_secret
npm startServer will run on http://localhost:5000 by default and hosted on https://medchainvaultbackend.onrender.com.
POST /upload– Upload a file (needs MetaMask-signed hash, wallet address)GET /getFile/:hash– Get file record by hash (checks access)GET /auditTrail– Get list of uploaded files (from blockchain events)POST /grantAccess– Grant file access to a wallet addressPOST /revokeAccess– Revoke file access for a wallet addressGET /canAccess/:fileHash/:address– Check if an address can access a file
- Upload: User uploads a file and signs its hash with MetaMask. Server stores file on IPFS and logs metadata to blockchain.
- Verify: Any user with access can verify a file’s authenticity using the blockchain.
- Access Control: Only the uploader can grant/revoke access for others, enforced by the smart contract.
- Never commit your
.envor private key to GitHub! - MetaMask signature is required for upload authentication.
- All smart contract interactions use Ethers.js.
- See
index.jsfor implementation. - Modify CORS if deploying frontend elsewhere.
Built by Team Hack Demons for hackathons and innovation!