Lottery Smart Contract

Lottery Smart Contract

Check it out

A decentralized lottery system built with Solidity on the Sepolia Testnet, ensuring transparent participation and fair winner selection with a fixed 10 wei fee.

Blockchain Developer

Personal Project

SolidityEthereumSepolia TestnetMetaMaskRemix IDEBlockchainSmart ContractDecentralized

Overview

This project is a decentralized lottery system I built using Solidity and deployed on the Sepolia Testnet, showcasing my skills in blockchain development and smart contract programming. It allows users to participate in a lottery by sending a fixed fee of 10 wei, with a transparent and fair winner selection process powered by a pseudo-random number generator. Designed with security and decentralization in mind, the contract restricts administrative actions to the manager, auto-resets after each round, and rewards the winner with the accumulated balance. Integrated with MetaMask and developed using Remix IDE, this project demonstrates my ability to create practical, trustless applications on the Ethereum blockchain.

Features

  • Decentralized Lottery: Ensures transparency and fairness via blockchain technology.
  • Secure Management: Restricts balance viewing and winner selection to the manager.
  • Auto-Reset Mechanism: Clears the player list after each winner, preparing for the next round.
  • Low Participation Fees: Affordable entry at just 10 wei per participant.
  • Random Winner Selection: Uses a pseudo-random generator for unbiased outcomes.
  • Winner Reward: Transfers the entire contract balance to the selected winner.

Technologies Used

  • Solidity: Programming language for writing the smart contract.
  • Ethereum Blockchain: Deployed on the Sepolia Testnet for testing and execution.
  • MetaMask: Wallet integration for user transactions and testing.
  • Remix IDE: Development environment for coding, testing, and deploying the contract.

How It Works

  1. Deploy: The contract is deployed on the Sepolia Testnet by the manager (contract creator).
  2. Participate:
    • Users join by sending exactly 10 wei to the contract via MetaMask.
    • Participant addresses are securely stored in the contract.
  3. Winner Selection:
    • The manager triggers winner selection after at least 3 players join.
    • A pseudo-random index is generated, and the winner receives the contract’s balance.
    • The player list resets automatically for the next round.

Design Screens

Contract Deployment Transaction in MetaMask

My Contributions

  • Smart Contract Development: Wrote the Solidity code for lottery logic, including participation, random selection, and reward distribution.
  • Deployment: Deployed the contract on Sepolia Testnet using Remix IDE.
  • Testing: Integrated MetaMask for transaction testing and validated functionality.
  • Security Design: Implemented manager-only access and minimum player checks for fairness.

Challenges Faced

Overcame challenges like ensuring a secure pseudo-random number generator in a deterministic blockchain environment, restricting administrative functions to the manager without vulnerabilities, and testing edge cases (e.g., insufficient fees) on Sepolia Testnet. Gas optimization for low-cost transactions was a key focus.

What I Learned

This project deepened my understanding of Solidity, smart contract security, and Ethereum blockchain mechanics. I gained hands-on experience with Remix IDE, MetaMask integration, and deploying on testnets, while learning the nuances of decentralized application design.

Future Improvements

Plans include integrating Chainlink VRF for cryptographically secure randomness, adding a frontend interface with React and ethers.js, and enabling multi-round lotteries with historical winner tracking.

Impact

This project serves as a practical demonstration of decentralized systems, offering a transparent, trustless lottery solution and showcasing my blockchain development capabilities for real-world applications.

And more, including gas optimization, smart contract best practices, and blockchain deployment workflows.