Decentralized Blockchain Lottery
Project Overview
I designed and developed a fully decentralized lottery system running on the Ethereum blockchain. This project leverages smart contract technology to create a transparent, fair, and automated lottery platform where all operations—from ticket purchases to prize distribution—are handled by immutable code rather than a centralized authority.
Technical Implementation
Smart Contract Architecture
Developed using Solidity 0.8.26 with a comprehensive state management system
Implemented a multi-phase lottery process (Active, Drawing, Registration, Claiming)
Integrated Chainlink VRF (Verifiable Random Function) for truly random, verifiable drawing results
Utilized Chainlink Automation for managing time-based state transitions without manual intervention
Incorporated robust error handling and validation systems for ticket purchases and prize claims
Key Technical Features
Random number generation using Chainlink's VRF to ensure provable fairness
Automated round management that extends the lottery if minimum participation thresholds aren't met
Two-step winning process requiring winners to actively register tickets, preventing unclaimed prizes
Prize pool rollover system when no winners are present
Gas-efficient operations using unchecked math operations where appropriate
Comprehensive event emission for front-end synchronization
Front End Development
Built with Next.js for server-side rendering and optimal performance
Styled using Tailwind CSS for responsive, modern UI design
Real-time blockchain interaction through Web3 integration
User-friendly interfaces for ticket purchases, checking results, and claiming prizes
User Experience
Users purchase tickets by selecting six unique numbers between 1-99. Each ticket costs 0.002 ETH. The lottery runs in weekly rounds with automated drawing using verifiably random numbers. Winners must register their tickets within a 3-hour window to claim their share of the prize pool, which consists of all ticket purchases minus a small 1% fee.
Technical Challenges Overcome
Implementing secure random number generation on blockchain (solved with Chainlink VRF)
Creating automated yet fair round transitions without human intervention
Designing an efficient winner verification and prize distribution system
Optimizing for gas costs while maintaining complete functionality
Technical Stack
Blockchain: Ethereum
Smart Contracts: Solidity
Testing Framework: Foundry
Frontend: TypeScript, Next.js, TailwindCss, ConnectKit, Viem, Wagmi
Backend: Express.js, Redis,
State Management: Zustand