Blockchain medical records system with end-to-end encryption using Oasis Sapphire.
โ Automatic Encryption: All data is encrypted on blockchain โ Access Control: Patients authorize which doctors can view their data โ Guaranteed Privacy: Data inaccessible without permissions โ Immutable: Permanent and verifiable medical history โ Easy to Use: Intuitive web interface
- Full name
- Age
- Gender
- Blood type
- Address
- Phone
- Social Security Number
- Disease name
- Diagnosis description
- Diagnosis date
- Severity (Mild, Moderate, Severe)
- Status (Active/Inactive)
- Treatment
- Personal: Surgeries, past illnesses, allergies
- Family: Hereditary conditions, family history
- Node.js v18+
- npm or yarn
- MetaMask installed
- TEST tokens from Sapphire Testnet
cd medical-records-sapphire
npm installcp .env.example .envEdit .env and add your private key:
PRIVATE_KEY=0xtu_clave_privada_aqui
- Go to https://faucet.testnet.oasis.io/
- Select "Sapphire"
- Enter your address
- Get 100 TEST tokens
npx hardhat compile# Option 1: Tests on Hardhat Network
npx hardhat test
# Option 2: Tests on Sapphire Localnet (more realistic)
# Terminal 1: Start localnet
docker run -it -p 8545:8545 ghcr.io/oasisprotocol/sapphire-localnet
# Terminal 2: Run tests
npx hardhat test --network sapphire-localnetnpx hardhat run scripts/deploy.js --network sapphire-testnetSave the contract address that appears in the console.
cd frontend
npm installCreate the .env file:
cp .env.example .envEdit frontend/.env:
VITE_CONTRACT_ADDRESS=0xDireccion_Del_Contrato_Desplegado
VITE_NETWORK=testnet
npm run devOpen http://localhost:3000 in your browser.
Add Sapphire Testnet manually:
- Open MetaMask
- Click on the network selector
- "Add Network" โ "Add Network Manually"
- Enter:
Network Name: Sapphire Testnet
RPC URL: https://testnet.sapphire.oasis.io
Chain ID: 23295
Currency Symbol: TEST
Block Explorer: https://explorer.oasis.io/testnet/sapphire
- Connect your wallet
- Go to the "๐ Registro" tab
- Fill out the form with your data
- Click "Registrar Paciente"
- Confirm the transaction in MetaMask
- Go to "๐ฉบ Enfermedades"
- Fill in the disease data
- Save (encrypted transaction)
- Go to "๐ Antecedentes"
- Select type (Personal/Family)
- Add the condition and details
- Go to "๐๏ธ Ver Registros"
- Leave your address (appears automatically)
- You will see all your encrypted data
- Go to "๐ Permisos"
- Enter the doctor's address
- Click "Autorizar Mรฉdico"
- The doctor can now view your history
- Connect your wallet
- Go to "๐ Registro"
- Enter your name in "Registrar Mรฉdico"
- The patient must authorize you first
- Go to "๐๏ธ Ver Registros"
- Enter the patient's address
- You will see their complete history
- Go to "๐ฉบ Enfermedades"
- Enter the patient's address (who authorized you)
- Add the disease and treatment
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ FRONTEND (React) โ
โ - Medical forms โ
โ - Data visualization โ
โ - Permission management โ
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโ
โ Wagmi + Sapphire Wrapper
โ (Automatic encryption)
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ SAPPHIRE BLOCKCHAIN (Testnet) โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Smart Contract โ โ
โ โ MedicalRecords.sol โ โ
โ โ โ โ
โ โ - Encrypted data in storage โ โ
โ โ - Access control โ โ
โ โ - Granular permissions โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
- Encrypted Storage: All contract storage is encrypted by default in Sapphire
- Encrypted Transactions: Wagmi wrapper automatically encrypts transactions
- TEE (Trusted Execution Environment): Data is only decrypted inside the TEE
- Access Control: Solidity modifiers prevent unauthorized access
- User addresses
- Timestamps
- Action confirmations
Sensitive data like names, diagnoses, etc. are NEVER emitted.
immutable and constant variables are NOT encrypted because they are stored in the bytecode.
// โ BAD - Visible data
bytes32 private constant SECRET = "mi_secreto";
// โ
GOOD - Encrypted data
bytes32 private secret;| Feature | Testnet | Mainnet |
|---|---|---|
| Confidentiality | โ Guaranteed | |
| Cost | ๐ Free | ๐ฐ ROSE tokens |
| Data | ๐งช Testing only | ๐ Real data |
npx hardhat testnpx hardhat coverage# Terminal 1
docker run -it -p 8545:8545 ghcr.io/oasisprotocol/sapphire-localnet
# Terminal 2
npx hardhat test --network sapphire-localnetmedical-records-sapphire/
โโโ contracts/
โ โโโ MedicalRecords.sol # Main contract
โโโ scripts/
โ โโโ deploy.js # Deployment script
โโโ test/
โ โโโ MedicalRecords.test.js # Tests
โโโ frontend/
โ โโโ src/
โ โ โโโ components/ # React components
โ โ โโโ config/
โ โ โ โโโ wagmi.js # Wagmi configuration
โ โ โโโ contracts/ # ABIs (generated)
โ โ โโโ styles/
โ โ โ โโโ App.css
โ โ โโโ App.jsx
โ โ โโโ main.jsx
โ โโโ index.html
โ โโโ package.json
โ โโโ vite.config.js
โโโ hardhat.config.js
โโโ package.json
โโโ README.md
Form with all encrypted affiliation fields.
Add diagnoses with severity and treatment.
Authorize/Revoke access to specific doctors.
Complete encrypted history accessible only with permissions.
- You can only register once per address
- Use another wallet to create another patient
- Verify that the patient has authorized you
- Confirm that you are registered as a doctor
- Verify that you have TEST tokens
- Confirm that you are on Sapphire Testnet
- Check MetaMask configuration
- Copy the correct address to
frontend/.env - Restart the frontend server (
npm run dev)
Ideas to expand the system:
- Medical Prescriptions: Issue encrypted prescriptions
- Medical Appointments: Scheduling system
- Notifications: Alerts for new diagnoses
- Export PDF: Generate medical reports
- Medical Images: Store X-rays, MRIs (IPFS + encryption)
- Laboratories: Integrate test results
- Pharmacies: Prescription verification
- Insurance: Controlled access for insurers
- Data Update: Modify existing diseases
- Search: Filter by disease type, date, etc.
- Multi-language: Support for multiple languages
- Audit: Log of who accessed what data
- Docs: https://docs.oasis.io/build/sapphire/
- Quickstart: https://docs.oasis.io/build/sapphire/quickstart/
- Examples: https://github.com/oasisprotocol/sapphire-paratime/tree/main/examples
- Docs: https://wagmi.sh/
- React Hooks: https://wagmi.sh/react/api/hooks
- Docs: https://hardhat.org/docs
Contributions are welcome. Please:
- Fork the project
- Create a branch for your feature (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
MIT License - Free to use for educational and commercial projects.
This project is an educational demonstration. For production use with real medical data:
- โ Audit the smart contract
- โ Deploy to Sapphire Mainnet (NOT testnet)
- โ Comply with regulations (HIPAA, GDPR, etc.)
- โ Implement robust authentication
- โ Add additional encryption on the frontend
- โ Backups and disaster recovery
- โ Consult with legal and medical experts
Questions or problems?
- Oasis Discord: https://oasis.io/discord
- GitHub Issues: [Your repo here]
- Documentation: README.md
- Oasis Sapphire - Confidential blockchain
- Solidity - Smart contracts
- Hardhat - Development framework
- React - Frontend
- Wagmi - Ethereum library for React
- Viem - TypeScript Ethereum interface
- Vite - Build tool
Made with โค๏ธ to improve privacy in digital health