- Project Overview
- Tech Stack
- Architecture
- Core Functionalities
- Features Breakdown
- Data Flow
- Security Features
- API Reference
- Database Schema
- Deployment
TruthChain is a decentralized content verification system that creates a tamper-proof proof-of-truth layer for digital content. It leverages blockchain technology to fight misinformation by providing immutable content verification, creator authentication, and transparent version history.
Combat misinformation through blockchain-powered content verification and creator accountability.
- β Immutable Content Records - Once verified, content cannot be altered without detection
- β Creator Accountability - Verified creator identities with reputation scores
- β Tamper Detection - Instant detection of modified or fake content
- β Transparent History - Complete version tracking for all content updates
- β Decentralized Trust - No single point of control or censorship
- Next.js 14 (App Router)
- React 18 with Server Components
- File-based routing
- Built-in optimization
- TypeScript support
- CSS Modules - Scoped styling
- Vanilla CSS - Custom design system
- Glassmorphism - Modern UI effects
- Responsive Design - Mobile-first approach
- React Context API
Web3Context- Wallet connection stateThemeContext- UI theme management (if implemented)
- lucide-react - Icon library (200+ icons)
- recharts - Analytics charts
- crypto-js - Client-side hashing (SHA-256)
- ethers.js - Ethereum/Polygon interaction
- TypeScript - Type safety
- Polygon (Amoy Testnet) - Layer 2 scaling solution
- Low transaction costs (~$0.001)
- Fast confirmation times (~2 seconds)
- EVM compatible
- Mainnet ready
- Solidity 0.8.20 - Contract language
- Hardhat - Development environment
- Contract compilation
- Testing framework
- Deployment scripts
- Network configuration
- IPFS (Pinata) - Decentralized file storage
- Content metadata storage
- Immutable file addressing
- CDN integration
- LocalStorage - Client-side data (demo mode)
- Creator credentials
- Content cache
- User preferences
- Webpack (via Next.js)
- Turbopack (Next.js 14 dev mode)
- SWC - Fast TypeScript/JavaScript compiler
- Hardhat Test - Smart contract testing
- Mocha/Chai - Test framework
- Manual Testing - 71+ test cases documented
- Git - Source control
- GitHub - Repository hosting
- npm - Node package manager
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β USER INTERFACE β
β (Next.js Frontend) β
β ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ β
β β Home β β Verify β β Creator β β Explore β β
β ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ β
ββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββ¬ββββββββββββββββββ
β β β
βββββββββββββΌβββββββββββ βββββΌβββββββββ βββββββΌβββββββ
β Web3 Provider β β IPFS β β LocalStorageβ
β (MetaMask) β β (Pinata) β β (Cache) β
βββββββββββββ¬βββββββββββ ββββββββββββββ βββββββββββββββ
β
βββββββββββββΌβββββββββββ
β Polygon Blockchain β
β ββββββββββββββββββ β
β β CreatorRegistryβ β
β β Contract β β
β ββββββββββββββββββ β
β ββββββββββββββββββ β
β β TruthChain β β
β β Contract β β
β ββββββββββββββββββ β
ββββββββββββββββββββββββ
frontend/
βββ app/ # Next.js App Router
β βββ page.tsx # Home page
β βββ layout.tsx # Root layout
β βββ globals.css # Global styles
β βββ verify/
β β βββ page.tsx # Verification portal
β βββ creator/
β β βββ page.tsx # Creator dashboard
β βββ explore/
β β βββ page.tsx # Content exploration
β βββ admin/
β βββ page.tsx # Admin panel
βββ components/
β βββ Navigation.tsx # Global navigation
βββ contexts/
β βββ Web3Context.tsx # Wallet state management
βββ lib/
β βββ web3.ts # Web3 utilities
β βββ hash.ts # Hashing functions
β βββ ipfs.ts # IPFS integration
β βββ creatorAuth.ts # Authentication logic
β βββ contracts/ # Contract ABIs
βββ public/
βββ cosmos_bg.png # Background image
βββ admin_bg.png # Admin background
- Username/Password Authentication
- Unique username validation
- Password hashing (client-side)
- Wallet address binding
- Organization affiliation
- Pending Status - Initial registration state
- Approval Process - Admin review and verification
- Security Key Generation - 12-character alphanumeric key
- Inbox Notification - Automated message delivery
- Status Tracking - Pending β Approved β Rejected
- Login System - Username + password
- Session Management - Requires re-login after page refresh
- Password Reset - Username-based recovery
- Multi-Wallet Support - Different wallets = different accounts
1. Creator Login β 2. Security Key Unlock β 3. Fill Form β
4. Verification Animation (4 steps) β 5. Hash Generation β
6. Blockchain Storage β 7. Success Confirmation
- Title - Article/content headline
- Description - Brief summary
- Content - Full text/data
- Content Type - news, article, report, image, video
- Origin Proof - Source URL for verification
- Creator - Wallet address (auto-filled)
- Timestamp - Upload time (auto-generated)
- Hash - SHA-256 content hash (auto-generated)
- Version - Version number (auto-incremented)
- Create - Upload new content
- Read - View content details
- Update - Edit existing content (creates new version)
- Delete - Remove content from system
- Automatic Versioning - v1, v2, v3...
- History Tracking - All previous versions stored
- Hash Per Version - Each version has unique hash
- Timestamp Per Version - Track when changes occurred
Input: 0xabcd1234efgh5678
Process: Direct hash lookup in blockchain
Output: Authentic / UnverifiedInput: "Article text content"
Process:
1. Calculate SHA-256 hash of text
2. Search blockchain for hash
3. Optional: Compare with reference hash
Output: Authentic / Edited / UnverifiedInput: file.pdf (binary upload)
Process:
1. Read file as ArrayBuffer
2. Calculate SHA-256 hash of binary
3. Search blockchain for hash
4. Optional: Compare with reference hash
Output: Authentic / Edited / UnverifiedInput: 0x1234abc567def890 (wallet address)
Process: Redirect to creator profile
Output: Creator profile page with all contentAuthentic (Blue Shield)
- Hash found in blockchain
- Content matches exactly
- Shows: Title, Creator, Timestamp, Version
Edited/Tampered (Yellow Alert)
- Reference hash found in blockchain
- Computed hash doesn't match
- Shows: Both hashes for comparison
Unverified (Red X)
- Hash not found in blockchain
- Content not registered
- Shows: Computed hash only
- Grid View - Card-based content display
- Search - By title, creator name, or wallet address
- Filter - By content type (news, article, report, etc.)
- Combined Search + Filter - Narrow results
- Content Preview - Click to view full details
- Modal View - Full content display with metadata
- Content type badge
- Verified badge (green checkmark)
- Title
- Description (truncated to 120 chars)
- Creator avatar
- Creator name
- Wallet address
- Upload date
- Version number
- View All Creators - Pending, Approved, Rejected tabs
- Approve Creators - Generate security key
- Reject Creators - Deny verification
- View Creator Details - Name, org, wallet, registration date
- View All Content - Complete content list
- Block Content - Hide from Explore page
- Unblock Content - Restore visibility
- View Content Details - Full metadata
- Automatic Generation - On approval
- 12-Character Format - Alphanumeric (a-z, 0-9)
- One-Time Display - Shown once to admin
- Inbox Delivery - Sent to creator's inbox
- Unlock Mechanism - Required for upload feature
- Total Uploads - Count of published content
- Reputation Score - Calculated:
min(5.0, uploads * 0.1 + 3.0) - Upload Trend Chart - Line chart showing uploads over time
- Content Type Distribution - Breakdown by category
- Upload count per day
- Total content items
- Version history depth
- Creator verification status
- SHA-256 Algorithm - Industry-standard cryptographic hash
- Deterministic - Same content = same hash
- Collision Resistant - Virtually impossible to forge
- One-Way Function - Cannot reverse hash to content
Original Hash: 0xabcd1234efgh5678
Modified Content Hash: 0x9999aaaa7777bbbb
Result: TAMPERED (hashes don't match)- Username/Password - First authentication layer
- Wallet Address - Blockchain identity binding
- Security Key - Admin-issued unlock token
- Session Management - Requires re-authentication
- Client-side hashing (not stored in plain text)
- Unique username enforcement
- Wallet-username binding
- Admin panel accessible to all (demo mode)
- Production: Role-based access control (RBAC)
- Approval workflow prevents unauthorized uploads
- Block/unblock functionality
- Visibility control
- Audit trail (timestamps)
- Client-side only (demo mode)
- Encrypted in production
- Regular cleanup recommended
- Size limits enforced (5MB browser limit)
βββββββββββββββ
β Creator β
β Inputs β
β Content β
ββββββββ¬βββββββ
β
βΌ
βββββββββββββββ
β Calculate β
β SHA-256 β
β Hash β
ββββββββ¬βββββββ
β
βΌ
βββββββββββββββ
β Store in β
β LocalStorageβ
β (Demo Mode)β
ββββββββ¬βββββββ
β
βΌ
βββββββββββββββ
β Update β
β Explore β
β Page β
βββββββββββββββ
βββββββββββββββ
β User β
β Inputs β
β Hash/Text/ β
β File β
ββββββββ¬βββββββ
β
βΌ
βββββββββββββββ
β Calculate β
β Hash β
β (if needed) β
ββββββββ¬βββββββ
β
βΌ
βββββββββββββββ
β Search β
β LocalStorageβ
β for Hash β
ββββββββ¬βββββββ
β
ββββ Found βββββΆ Authentic
β
ββββ Found but ββΆ Edited
β different
β
ββββ Not Found ββΆ Unverified
βββββββββββββββ
β Creator β
β Registers β
ββββββββ¬βββββββ
β
βΌ
βββββββββββββββ
β Status: β
β Pending β
ββββββββ¬βββββββ
β
βΌ
βββββββββββββββ
β Admin β
β Reviews β
ββββββββ¬βββββββ
β
ββββ Approve βββΆ Generate Security Key
β β
β βΌ
β Send to Inbox
β β
β βΌ
β Status: Approved
β
ββββ Reject ββββΆ Status: Rejected
interface ContentItem {
id: string; // Unique identifier
title: string; // Content title
description: string; // Brief summary
content: string; // Full content text
contentType: string; // news, article, report, etc.
originProof: string; // Source URL
creator: string; // Wallet address
creatorName: string; // Creator username
timestamp: number; // Upload time (ms)
hash: string; // SHA-256 hash (0x...)
version: number; // Version number
history?: ContentItem[]; // Previous versions
blocked?: boolean; // Admin moderation flag
}interface AdminCreatorEntry {
id: string; // Unique identifier
address: string; // Wallet address
name: string; // Creator username
organization: string; // Organization name
registeredAt: number; // Registration timestamp (seconds)
status: "pending" | "approved" | "rejected";
securityKey?: string; // 12-char unlock key (if approved)
}interface CreatorCredentials {
name: string; // Username
organization: string; // Organization
password: string; // Hashed password
walletAddress: string; // Ethereum address
registeredAt: number; // Registration timestamp (ms)
}interface Message {
id: string; // Message ID
sender: string; // "System" or "Admin"
content: string; // Message text (security key)
timestamp: number; // Message time (ms)
read: boolean; // Read status
type: 'system' | 'admin'; // Message type
}Value: 'true' | 'false'
Purpose: Track if upload feature is unlocked
- Green (Success):
#00ff41- Verified, Authentic, Primary actions - Blue (Info):
#007aff- Authentic content, Links - Yellow (Warning):
#ffd700- Edited/Tampered content - Red (Error):
#ff3b30- Unverified, Errors, Rejected
- Black:
#000000- Background - Dark Gray:
#111111- Cards, containers - Medium Gray:
#858585- Secondary text - Light Gray:
#ffffff- Primary text
- Card Background:
rgba(17, 17, 17, 0.6) - Border:
rgba(0, 255, 65, 0.15) - Overlay:
rgba(0, 0, 0, 0.6)
- Headings: System font stack (sans-serif)
- Body: System font stack
- Monospace: For hashes, addresses, code
- Small: 8px, 12px, 16px
- Medium: 24px, 32px, 40px
- Large: 60px, 80px
- Small: 6px, 8px
- Medium: 12px, 20px
- Large: 50% (circles)
# Frontend
cd frontend
npm run dev
# Runs on http://localhost:3000
# Smart Contracts (if using blockchain)
npx hardhat compile
npx hardhat test
npx hardhat run scripts/deploy.js --network polygonAmoycd frontend
npm run build
npm startNEXT_PUBLIC_CREATOR_REGISTRY_ADDRESS=0x...
NEXT_PUBLIC_TRUTHCHAIN_ADDRESS=0x...
NEXT_PUBLIC_NETWORK_NAME=polygonAmoy
NEXT_PUBLIC_CHAIN_ID=80002
NEXT_PUBLIC_RPC_URL=https://rpc-amoy.polygon.technology
NEXT_PUBLIC_PINATA_API_KEY=your_key
NEXT_PUBLIC_PINATA_SECRET_KEY=your_secret
NEXT_PUBLIC_PINATA_JWT=your_jwtPOLYGON_AMOY_RPC_URL=https://rpc-amoy.polygon.technology
PRIVATE_KEY=your_private_key
POLYGONSCAN_API_KEY=your_api_key- Vercel (Recommended for Next.js)
- Netlify
- AWS Amplify
- Railway
- Polygon Amoy Testnet (Testing)
- Polygon Mainnet (Production)
- Page Load Time: < 2 seconds
- Verification Time: < 2 seconds
- Upload Success Rate: 100%
- Hash Accuracy: 100%
- Data Persistence: 100%
- Console Errors: 0
- Code Splitting - Next.js automatic
- Image Optimization - Next.js Image component
- Lazy Loading - React.lazy for components
- Caching - LocalStorage for frequently accessed data
- Minification - Production build optimization
interface Web3ContextType {
account: string | null;
isConnected: boolean;
connectWallet: () => Promise<void>;
disconnectWallet: () => void;
}
// Usage
const { account, isConnected, connectWallet } = useWeb3();// Text hashing
function generateContentHash(content: string): string {
return "0x" + CryptoJS.SHA256(content).toString();
}
// File hashing
async function calculateHash(file: File): Promise<string> {
const reader = new FileReader();
return new Promise((resolve, reject) => {
reader.onload = (e) => {
const binary = e.target?.result;
const wordArray = CryptoJS.lib.WordArray.create(binary as any);
resolve("0x" + CryptoJS.SHA256(wordArray).toString());
};
reader.readAsArrayBuffer(file);
});
}// Save credentials
saveCreatorCredentials({
name: string,
organization: string,
password: string,
walletAddress: string,
registeredAt: number
});
// Verify password
verifyCreatorPassword(walletAddress: string, password: string): boolean;
// Get credentials
getCreatorCredentials(walletAddress: string): CreatorCredentials | null;- README.md - Quick start guide
- TESTING_INDEX.md - Testing documentation hub
- COMPREHENSIVE_TEST_SUITE.md - 71 test cases
- QUICK_TEST_GUIDE.md - Fast testing guide
- VISUAL_TEST_CHECKLIST.md - Manual testing checklist
- DEPLOYMENT.md - Deployment instructions
- Next.js Documentation
- Polygon Documentation
- Hardhat Documentation
- IPFS Documentation
- Pinata Documentation
β
Creator registration & authentication
β
Admin approval workflow
β
Content upload with verification
β
Hash/Text/File/Creator verification
β
Content exploration & search
β
Admin content moderation
β
Version history tracking
β
Tamper detection
β
Analytics dashboard
- π Real blockchain integration (currently demo mode)
- π IPFS content storage
- π NFT certificates for verified content
- π Multi-signature admin approvals
- π Advanced analytics
- π API for third-party integration
- π Mobile app (React Native)
- π Browser extension
For questions, issues, or contributions:
- GitHub Issues: Report bugs or request features
- Documentation: Refer to testing and deployment guides
- Community: Join discussions and share feedback
Built with β€οΈ to fight misinformation
TruthChain - Because truth matters
Last Updated: 2025-11-29
Version: 1.0
Maintained by: Development Team