Skip to content

๐Ÿ” A comprehensive blockchain-based file verification system using Ethereum smart contracts. Features secure file integrity verification through cryptographic hashing and immutable blockchain storage.

License

Notifications You must be signed in to change notification settings

Sandarsh18/Blockchain-file-verification

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

6 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ” Blockchain File Verification System

Blockchain Smart Contract Frontend Backend License

A comprehensive decentralized file verification system built on the Ethereum blockchain that ensures file integrity and authenticity through cryptographic hashing and immutable blockchain storage.

๐ŸŒŸ Overview

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.

overview

๐Ÿ—๏ธ Architecture Overview

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   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 โ”€โ”€โ”˜

โœจ Key Features

๐Ÿ”’ Decentralized Security

  • File hashes stored immutably on Ethereum blockchain
  • No central authority can tamper with records
  • Cryptographic SHA-256 hashing ensures data integrity

๐ŸŒ Full-Stack Solution

  • 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

๐ŸŽฏ User-Friendly Interface

  • Drag-and-drop file upload
  • Real-time server status indicators
  • Detailed transaction information
  • Mobile-responsive design

๐Ÿ”ง Developer Features

  • Comprehensive test suite
  • Gas usage optimization
  • Error handling and logging
  • Health monitoring endpoints

๐Ÿš€ Quick Start Guide

๐Ÿ“‹ Prerequisites

Before you begin, ensure you have the following installed:

๐Ÿ”ง Installation & Setup

1๏ธโƒฃ Clone the Repository

git clone https://github.com/swasthikdevadiga1/BlockChain-SocGen.git
cd BlockChain-SocGen

2๏ธโƒฃ Install Dependencies

# Install root dependencies (blockchain & backend)
npm install

# Install frontend dependencies
npm install --prefix client

3๏ธโƒฃ Start Local Blockchain ๐ŸŒ

# Terminal 1: Start Hardhat local blockchain
npm run node

๐Ÿ’ก Tip: Keep this terminal running. You'll see 20 test accounts with ETH for development.

4๏ธโƒฃ Deploy Smart Contract ๐Ÿ“œ

# Terminal 2: Deploy the FileVerification contract
npm run deploy

โœ… Success: This creates a .env file with contract address and private key.

5๏ธโƒฃ Start Backend Server ๐Ÿ–ฅ๏ธ

# Terminal 3: Start the API server
npm start

๐Ÿš€ Running: Backend API available at http://localhost:4000

6๏ธโƒฃ Launch Frontend ๐ŸŒŸ

# Terminal 4: Start React application
npm run client

๐ŸŽ‰ Ready: Open http://localhost:3000 in your browser!

๐Ÿ—๏ธ System Architecture

๐Ÿ“Š Component Diagram

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
Loading

๐Ÿ”„ Data Flow Diagram

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
Loading

๐Ÿ”— API Documentation

๐Ÿ“ก Backend Endpoints

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

๐Ÿ“‹ API Examples

1๏ธโƒฃ Upload File

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
}

2๏ธโƒฃ Verify File

curl -X POST \
  -F "file=@document.pdf" \
  http://localhost:4000/verify

Response:

{
  "valid": true,
  "hash": "0x742d35cc...",
  "message": "File is verified and authentic",
  "success": true
}

3๏ธโƒฃ Health Check

curl http://localhost:4000/health

Response:

{
  "status": "healthy",
  "blockchain": {
    "connected": true,
    "network": "localhost",
    "chainId": "31337"
  },
  "contract": {
    "address": "0x5FbDB2315...",
    "walletBalance": "9999.99"
  }
}

๐Ÿงช Testing Suite

๐Ÿ”ฌ Smart Contract Tests

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

๐Ÿ› Manual Testing

Test Scenario 1: Basic Upload & Verify

# 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

Test Scenario 2: File Tampering Detection

# 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

๐Ÿ”ง Configuration & Environment

๐Ÿ“„ Environment Variables

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

โš™๏ธ Available Scripts

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

๐Ÿ› ๏ธ Technology Stack

Frontend

  • 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

Backend

  • 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

Blockchain

  • Solidity ^0.8.0 - Smart contract programming language
  • Hardhat - Ethereum development environment
  • OpenZeppelin - Security-focused contract libraries

Development Tools

  • Hardhat Network - Local blockchain for testing
  • Chai/Mocha - Testing framework
  • ESLint - Code linting
  • Nodemon - Development server auto-restart

๐Ÿ” Security Features

๐Ÿ›ก๏ธ Smart Contract Security

  • 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

๐Ÿ”’ Data Privacy

  • 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

๐Ÿšจ Error Handling

  • 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

๐Ÿ“Š Performance Metrics

โ›ฝ Gas Usage

  • Contract Deployment: ~223,466 gas
  • Upload File Hash: ~45,588 gas
  • Verify File Hash: ~23,000 gas (view function)

๐Ÿš€ Response Times

  • File Upload: 2-5 seconds (including blockchain confirmation)
  • File Verification: <1 second (read-only operation)
  • Health Check: <100ms

๐ŸŒ Deployment Guide

๐Ÿ  Local Development

Already covered in the Quick Start Guide above.

โ˜๏ธ Production Deployment

Backend Deployment (Railway/Heroku)

# 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

Frontend Deployment (Vercel/Netlify)

cd client
npm run build

# Deploy build folder to hosting service

Smart Contract Deployment (Mainnet)

# 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.

๐Ÿ”„ How It Works

1๏ธโƒฃ File Processing

User File โ†’ SHA-256 Hash โ†’ Blockchain Storage

2๏ธโƒฃ Hash Generation

  • Files are processed client-side using SHA-256 algorithm
  • Generates unique 256-bit fingerprint for each file
  • Same file always produces same hash (deterministic)

3๏ธโƒฃ Blockchain Storage

mapping(bytes32 => bool) public fileHashes;

function uploadFile(bytes32 hash) public {
    require(!fileHashes[hash], "File already uploaded");
    fileHashes[hash] = true;
    emit FileUploaded(hash);
}

4๏ธโƒฃ Verification Process

  • Calculate hash of file to verify
  • Query blockchain for hash existence
  • Return verification result

๐Ÿ“ˆ Project Roadmap

โœ… Completed Features

  • Basic file verification system
  • Smart contract deployment
  • Frontend user interface
  • Backend API development
  • Comprehensive testing suite
  • Error handling & logging

๐Ÿšง In Progress

  • MetaMask integration
  • File metadata storage
  • Bulk file verification
  • Advanced analytics dashboard

๐Ÿ”ฎ Future Enhancements

  • IPFS integration for file storage
  • Multi-chain support (Polygon, Arbitrum)
  • API rate limiting
  • File expiration system
  • Digital signatures integration
  • Audit trail reporting
  • Mobile application

๐Ÿค Contributing

We welcome contributions! Please follow these steps:

๐Ÿ”ง Development Setup

  1. Fork the repository
  2. Create feature branch: git checkout -b feature/amazing-feature
  3. Follow coding standards and add tests
  4. Commit changes: git commit -m 'Add amazing feature'
  5. Push to branch: git push origin feature/amazing-feature
  6. Create Pull Request

๐Ÿ“‹ Contribution Guidelines

  • Write clear, concise commit messages
  • Add tests for new features
  • Update documentation as needed
  • Follow existing code style
  • Ensure all tests pass

๐Ÿ› Bug Reports

Please include:

  • Operating system and version
  • Node.js version
  • Clear reproduction steps
  • Expected vs actual behavior
  • Screenshots if applicable

๐Ÿ†˜ Troubleshooting

โ“ Common Issues

"Server is not connected"

# Check if backend server is running
curl http://localhost:4000/health

# Restart backend server
npm start

"Contract not deployed"

# Redeploy smart contract
npm run deploy

# Check .env file exists with CONTRACT_ADDRESS
cat .env

"Transaction failed"

  • Ensure Hardhat node is running
  • Check wallet has sufficient ETH
  • Verify network connection
  • Try with different file

"High gas usage"

  • Use smaller files for testing
  • Check network congestion
  • Consider gas price optimization

๐Ÿ“ž Support & Contact

  • ๐Ÿ› Issues: GitHub Issues
  • ๐Ÿ’ฌ Discussions: GitHub Discussions
  • ๐Ÿ“ง Email: Contact repository owner
  • ๐Ÿ“– Documentation: See this README and inline code comments

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • 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

About

๐Ÿ” A comprehensive blockchain-based file verification system using Ethereum smart contracts. Features secure file integrity verification through cryptographic hashing and immutable blockchain storage.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •