A comprehensive decentralized file verification system built on the Ethereum blockchain that ensures file integrity and authenticity through cryptographic hashing and immutable blockchain storage.
This project demonstrates a robust file verification system using the Ethereum blockchain. Users can upload file hashes to a smart contract and later verify file integrity by checking if the hash exists on the blockchain. The system provides a tamper-proof, decentralized solution for document authenticity verification.
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ React Client โ โ Node.js API โ โ Ethereum Networkโ
โ โ โ โ โ โ
โ โข File Upload โโโโโบโ โข Express.js โโโโโบโ โข Smart Contractโ
โ โข Verification โ โ โข Multer โ โ โข File Hashes โ
โ โข UI/UX โ โ โข Ethers.js โ โ โข Immutable โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ โ โ
โโโโโโโ HTTP Requests โโโโโ โโโ Web3 Calls โโโ
- File hashes stored immutably on Ethereum blockchain
- No central authority can tamper with records
- Cryptographic SHA-256 hashing ensures data integrity
- Smart Contract: Solidity-based contract for hash storage
- Backend API: Node.js/Express server with RESTful endpoints
- Frontend: Modern React application with responsive design
- Development Environment: Complete Hardhat setup
- Drag-and-drop file upload
- Real-time server status indicators
- Detailed transaction information
- Mobile-responsive design
- Comprehensive test suite
- Gas usage optimization
- Error handling and logging
- Health monitoring endpoints
Before you begin, ensure you have the following installed:
- Node.js (v16 or later) - Download here
- npm (v8 or later) - Comes with Node.js
- Git - Download here
git clone https://github.com/swasthikdevadiga1/BlockChain-SocGen.git
cd BlockChain-SocGen
# Install root dependencies (blockchain & backend)
npm install
# Install frontend dependencies
npm install --prefix client
# Terminal 1: Start Hardhat local blockchain
npm run node
๐ก Tip: Keep this terminal running. You'll see 20 test accounts with ETH for development.
# Terminal 2: Deploy the FileVerification contract
npm run deploy
โ Success: This creates a
.env
file with contract address and private key.
# Terminal 3: Start the API server
npm start
๐ Running: Backend API available at
http://localhost:4000
# Terminal 4: Start React application
npm run client
๐ Ready: Open
http://localhost:3000
in your browser!
graph TB
subgraph "Frontend Layer"
A[React Client] --> B[File Upload UI]
A --> C[Verification UI]
A --> D[Status Dashboard]
end
subgraph "Backend Layer"
E[Express.js API] --> F[File Processing]
E --> G[Blockchain Interface]
E --> H[Error Handling]
end
subgraph "Blockchain Layer"
I[Smart Contract] --> J[Hash Storage]
I --> K[Verification Logic]
I --> L[Event Emission]
end
A -.->|HTTP/HTTPS| E
G -.->|Web3 Calls| I
style A fill:#61dafb,stroke:#333,stroke-width:2px
style E fill:#68c946,stroke:#333,stroke-width:2px
style I fill:#f7931e,stroke:#333,stroke-width:2px
sequenceDiagram
participant User as ๐ค User
participant Client as ๐ React Client
participant API as ๐ฅ๏ธ Backend API
participant BC as โ๏ธ Blockchain
User->>Client: 1. Select File
Client->>Client: 2. Calculate SHA-256 Hash
Client->>API: 3. POST /upload {file}
API->>API: 4. Hash File Content
API->>BC: 5. Call uploadFile(hash)
BC-->>API: 6. Transaction Receipt
API-->>Client: 7. Success Response
Client-->>User: 8. Show Confirmation
Note over User,BC: File Verification Flow
User->>Client: 9. Select Same File
Client->>API: 10. POST /verify {file}
API->>BC: 11. Call verifyFile(hash)
BC-->>API: 12. Boolean Result
API-->>Client: 13. Verification Result
Client-->>User: 14. Show Status
The backend server provides RESTful API endpoints for blockchain interaction:
Method | Endpoint | Description | Request | Response |
---|---|---|---|---|
POST |
/upload |
Upload file hash to blockchain | multipart/form-data |
Transaction details |
POST |
/verify |
Verify file against blockchain | multipart/form-data |
Verification result |
GET |
/health |
Server and blockchain status | None | Health information |
GET |
/contract-info |
Contract details | None | Contract address & wallet |
curl -X POST \
-F "file=@document.pdf" \
http://localhost:4000/upload
Response:
{
"message": "File uploaded successfully to blockchain",
"hash": "0x742d35cc...",
"transactionHash": "0x1234567...",
"blockNumber": 42,
"gasUsed": "45588",
"success": true
}
curl -X POST \
-F "file=@document.pdf" \
http://localhost:4000/verify
Response:
{
"valid": true,
"hash": "0x742d35cc...",
"message": "File is verified and authentic",
"success": true
}
curl http://localhost:4000/health
Response:
{
"status": "healthy",
"blockchain": {
"connected": true,
"network": "localhost",
"chainId": "31337"
},
"contract": {
"address": "0x5FbDB2315...",
"walletBalance": "9999.99"
}
}
Run comprehensive smart contract tests:
# Run all tests
npm test
# Run specific test file
npx hardhat test test/FileVerification.js
# Run tests with gas reporting
REPORT_GAS=true npm test
Test Coverage:
- โ Contract deployment
- โ File hash upload functionality
- โ Duplicate hash prevention
- โ File verification logic
- โ Multiple file handling
- โ Gas usage optimization
# Create test file
echo "Hello Blockchain!" > test.txt
# Upload to blockchain
curl -X POST -F "file=@test.txt" http://localhost:4000/upload
# Verify file
curl -X POST -F "file=@test.txt" http://localhost:4000/verify
# Upload original file
echo "Original content" > original.txt
curl -X POST -F "file=@original.txt" http://localhost:4000/upload
# Modify file content
echo "Modified content" > original.txt
# Verify (should fail)
curl -X POST -F "file=@original.txt" http://localhost:4000/verify
Create a .env
file in the root directory:
# Auto-generated by deployment script
CONTRACT_ADDRESS=0x5FbDB2315678afecb367f032d93F642f64180aa3
PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
# Optional configurations
PORT=4000
NETWORK_URL=http://localhost:8545
Script | Command | Description |
---|---|---|
Start Backend | npm start |
Launch API server |
Start Frontend | npm run client |
Launch React app |
Deploy Contract | npm run deploy |
Deploy to localhost |
Run Tests | npm test |
Execute test suite |
Start Blockchain | npm run node |
Launch Hardhat node |
Compile Contracts | npm run compile |
Compile Solidity |
- React 18 - Modern UI library with hooks
- Axios - HTTP client for API requests
- CSS3 - Custom styling with gradients and animations
- Responsive Design - Mobile-first approach
- Node.js - Runtime environment
- Express.js - Web application framework
- Multer - File upload middleware
- Ethers.js - Ethereum library for blockchain interaction
- CORS - Cross-origin resource sharing
- Solidity ^0.8.0 - Smart contract programming language
- Hardhat - Ethereum development environment
- OpenZeppelin - Security-focused contract libraries
- Hardhat Network - Local blockchain for testing
- Chai/Mocha - Testing framework
- ESLint - Code linting
- Nodemon - Development server auto-restart
- Reentrancy Protection: Functions are designed to prevent reentrancy attacks
- Access Control: No admin privileges - fully decentralized
- Input Validation: Strict hash format validation
- Gas Optimization: Efficient storage patterns to minimize costs
- Hash-Only Storage: Only SHA-256 hashes are stored, not file content
- No Personal Data: Zero collection of user information
- Client-Side Hashing: Files never leave user's browser for privacy
- Immutable Records: Blockchain ensures data cannot be altered
- Network Disconnection: Graceful handling of blockchain connectivity issues
- Transaction Failures: Detailed error messages for failed transactions
- File Size Limits: 10MB maximum file size protection
- Duplicate Prevention: Smart contract prevents duplicate hash uploads
- Contract Deployment: ~223,466 gas
- Upload File Hash: ~45,588 gas
- Verify File Hash: ~23,000 gas (view function)
- File Upload: 2-5 seconds (including blockchain confirmation)
- File Verification: <1 second (read-only operation)
- Health Check: <100ms
Already covered in the Quick Start Guide above.
# Build for production
npm run build
# Set environment variables
export CONTRACT_ADDRESS=your_contract_address
export PRIVATE_KEY=your_private_key
export NETWORK_URL=https://mainnet.infura.io/v3/YOUR_KEY
# Deploy
git push heroku main
cd client
npm run build
# Deploy build folder to hosting service
# Update hardhat.config.js with mainnet settings
npx hardhat run scripts/deploy.js --network mainnet
โ ๏ธ Important: Use environment variables for private keys in production. Never commit private keys to version control.
User File โ SHA-256 Hash โ Blockchain Storage
- Files are processed client-side using SHA-256 algorithm
- Generates unique 256-bit fingerprint for each file
- Same file always produces same hash (deterministic)
mapping(bytes32 => bool) public fileHashes;
function uploadFile(bytes32 hash) public {
require(!fileHashes[hash], "File already uploaded");
fileHashes[hash] = true;
emit FileUploaded(hash);
}
- Calculate hash of file to verify
- Query blockchain for hash existence
- Return verification result
- Basic file verification system
- Smart contract deployment
- Frontend user interface
- Backend API development
- Comprehensive testing suite
- Error handling & logging
- MetaMask integration
- File metadata storage
- Bulk file verification
- Advanced analytics dashboard
- IPFS integration for file storage
- Multi-chain support (Polygon, Arbitrum)
- API rate limiting
- File expiration system
- Digital signatures integration
- Audit trail reporting
- Mobile application
We welcome contributions! Please follow these steps:
- Fork the repository
- Create feature branch:
git checkout -b feature/amazing-feature
- Follow coding standards and add tests
- Commit changes:
git commit -m 'Add amazing feature'
- Push to branch:
git push origin feature/amazing-feature
- Create Pull Request
- Write clear, concise commit messages
- Add tests for new features
- Update documentation as needed
- Follow existing code style
- Ensure all tests pass
Please include:
- Operating system and version
- Node.js version
- Clear reproduction steps
- Expected vs actual behavior
- Screenshots if applicable
# Check if backend server is running
curl http://localhost:4000/health
# Restart backend server
npm start
# Redeploy smart contract
npm run deploy
# Check .env file exists with CONTRACT_ADDRESS
cat .env
- Ensure Hardhat node is running
- Check wallet has sufficient ETH
- Verify network connection
- Try with different file
- Use smaller files for testing
- Check network congestion
- Consider gas price optimization
- ๐ Issues: GitHub Issues
- ๐ฌ Discussions: GitHub Discussions
- ๐ง Email: Contact repository owner
- ๐ Documentation: See this README and inline code comments
This project is licensed under the MIT License - see the LICENSE file for details.
- OpenZeppelin for smart contract security patterns
- Hardhat for excellent development tools
- React team for the amazing frontend framework
- Ethereum community for blockchain infrastructure
- Contributors who helped improve this project
โญ Star this project if you find it helpful!
Made with โค๏ธ by the blockchain community