A decentralized digital identity and data sharing platform for healthcare, built on Ethereum-compatible smart contracts. Patients retain control over access to their medical records, and healthcare providers can only view data with explicit, time-bound consent.
- Prerequisites
- Installation
- Configuration
- Running the Application
- Testing
- Project Structure
- Technology Stack
- Cleanup
- Troubleshooting
Before installing, ensure you have the following installed on your system:
-
Node.js (v18.0.0 or higher)
- Download from: https://nodejs.org/
- Verify installation:
node --version npm --version
-
Git
- Download from: https://git-scm.com/
- Verify installation:
git --version
-
A modern web browser (Chrome, Firefox, Safari, or Edge)
- Operating System: macOS, Linux, or Windows
- RAM: Minimum 4GB (8GB recommended)
- Disk Space: At least 500MB free space
- Internet Connection: Required for initial installation
git clone git@github.com:Rarees404/BlockChain.git
cd BlockChainInstall all required packages for the smart contracts and Hardhat:
npm installThis will install:
- Hardhat and development tools
- TypeScript and type definitions
- Viem for Ethereum interactions
- Testing frameworks
Navigate to the frontend directory and install frontend dependencies:
cd frontend
npm install
cd ..This will install:
- Next.js framework
- React and React DOM
- Wagmi for wallet connections
- UI components (shadcn/ui, Radix UI)
- Tailwind CSS
Verify that all dependencies are installed correctly:
# Check Hardhat installation
npx hardhat --version
# Check frontend dependencies
cd frontend
npm list --depth=0
cd ..After deploying contracts, update the contract addresses in:
File: frontend/lib/contracts/config.ts
The default addresses are for Hardhat's local network. After deployment, update them with the actual deployed addresses from the deployment output.
Note: The project is configured for local development using Hardhat's local network (Chain ID: 31337).
The application requires three separate terminal windows/tabs to run properly.
Start the local Hardhat blockchain network:
npx hardhat nodeKeep this terminal running. You should see:
- Account addresses and private keys
- Network information (Chain ID: 31337)
- Listening on http://127.0.0.1:8545
In a new terminal, deploy the smart contracts to the local network:
npx hardhat ignition deploy ignition/modules/Deploy.ts --network localhostImportant: Copy the deployed contract addresses from the output. You'll need to update frontend/lib/contracts/config.ts with these addresses.
The deployment will create:
DigitalIdentity.sol- Patient identity managementConsentManager.sol- Consent lifecycle managementDataSharing.sol- Data access control and audit loggingHealthToken.sol- ERC-20 token for rewards
In a third terminal, start the Next.js development server:
cd frontend
npm run devThe frontend will be available at: http://localhost:3000
Open your browser and navigate to:
http://localhost:3000
Available Pages:
/- Home page/register- Patient registration/consents- Consent management/data- Data registration/audit- Audit log viewer/wallet- Token wallet and rewards/doctor- Doctor/provider view/accounts- Account management
Execute the complete test suite:
npm testRun tests in watch mode for development:
npm run test:watchGenerate a detailed gas usage report:
npm run gas-reportThe test suite includes:
- Unit Tests: Individual contract functionality
- Integration Tests: End-to-end user workflows
- Gas Measurements: Cost analysis for each function
Test Files:
test/DigitalIdentity.test.ts- Identity registration teststest/ConsentManager.test.ts- Consent management teststest/DataSharing.test.ts- Data access teststest/HealthToken.test.ts- Token functionality teststest/Integration.test.ts- Complete workflow tests
BlockChain/
├── contracts/ # Solidity smart contracts
│ ├── DigitalIdentity.sol
│ ├── ConsentManager.sol
│ ├── DataSharing.sol
│ └── HealthToken.sol
├── test/ # Test files
│ ├── DigitalIdentity.test.ts
│ ├── ConsentManager.test.ts
│ ├── DataSharing.test.ts
│ ├── HealthToken.test.ts
│ └── Integration.test.ts
├── scripts/ # Utility scripts
│ ├── distribute-tokens.ts
│ └── generate-gas-report.ts
├── ignition/ # Hardhat Ignition deployment
│ └── modules/
│ └── Deploy.ts
├── frontend/ # Next.js frontend application
│ ├── app/ # Next.js app router pages
│ ├── components/ # React components
│ ├── lib/ # Utilities and configurations
│ └── public/ # Static assets
├── artifacts/ # Compiled contracts (generated)
├── cache/ # Hardhat cache (generated)
├── hardhat.config.ts # Hardhat configuration
├── package.json # Root dependencies
└── README.md # This file
- Solidity: 0.8.30
- Hardhat: Development environment and testing framework
- Viem: TypeScript Ethereum library
- Hardhat Ignition: Deployment framework
- Next.js: 16.0.3 (React framework)
- React: 19.2.0
- TypeScript: 5.x
- Wagmi: 2.9.0 (React hooks for Ethereum)
- Tailwind CSS: 4.x (Styling)
- shadcn/ui: Component library
- RainbowKit: Wallet connection UI
- TypeScript: Type-safe development
- ESLint: Code linting
- Node.js: Runtime environment
After each development session, clean generated files:
npm run cleanThis removes:
artifacts/directory (compiled contracts)cache/directory (Hardhat cache)ignition/deployments/chain-*directories (deployment artifacts)
To completely reset the blockchain state:
-
Stop Hardhat node (Ctrl+C in Terminal 1)
-
Clean deployment artifacts:
npm run clean
-
Clear browser localStorage (accounts created during testing):
- Open browser console (F12 or Cmd+Option+I)
- Run:
localStorage.removeItem("local_wallet_accounts") - Or clear all:
localStorage.clear() - Refresh the page
-
Restart Hardhat node:
npx hardhat node
Note:
- Accounts are generated fresh each time you start Hardhat node
- The blockchain state resets when you stop/restart the node
- Only deployment artifacts persist and need to be cleaned
- Accounts created via UI are stored in browser localStorage and persist until cleared
Problem: Frontend dependencies not installed.
Solution:
cd frontend
npm installProblem: Dependencies not installed or node_modules corrupted.
Solution:
# Root directory
rm -rf node_modules package-lock.json
npm install
# Frontend directory
cd frontend
rm -rf node_modules package-lock.json
npm installProblem: Another Hardhat node is already running.
Solution:
- Find and kill the process:
lsof -ti:8545 | xargs kill - Or use a different port in
hardhat.config.ts
Problem: Another Next.js app is running on port 3000.
Solution:
- Kill the process:
lsof -ti:3000 | xargs kill - Or run on a different port:
PORT=3001 npm run dev
Problem: Contracts not deployed or addresses not updated.
Solution:
- Deploy contracts:
npx hardhat ignition deploy ignition/modules/Deploy.ts --network localhost - Copy addresses from output
- Update
frontend/lib/contracts/config.ts
Problem: Insufficient balance or network mismatch.
Solution:
- Ensure Hardhat node is running
- Check that you're connected to the correct network (Chain ID: 31337)
- Hardhat node provides test accounts with ETH balance
Problem: Contracts not compiled or outdated artifacts.
Solution:
npx hardhat compile
npm testIf you encounter issues not covered here:
- Check the terminal output for detailed error messages
- Verify all prerequisites are installed correctly
- Ensure all three terminals are running (node, deploy, frontend)
- Check that contract addresses match in
config.ts - Clear browser cache and localStorage
- Restart all processes
npx hardhat compilenpx hardhat test test/Integration.test.tscd frontend
npm run build
npm startcd frontend
npm run lintProject: Decentralized Digital Identity and Data Sharing Platform
Use Case: Healthcare - Patient-Controlled Medical Records
License: MIT