Decentralized Lottery

Decentralized Lottery

Publish Date: Sep 8 '25
0 1

Dettery - decentralized lottery dApp (Ethereum testnet Sepolia).


I just launched dettery and testing the app.

Here is the markdown…(https://github.com/advexon/Dettery)

DETTERY - Decentralized Lottery Platform
License: MIT Solidity Next.js TypeScript Ethereum

A provably fair, transparent, and decentralized lottery system built on Ethereum Sepolia testnet with automatic payouts and secure randomness.
🌟 Features

🔒 Security & Transparency

✅ Smart Contract Verified - All contracts are verified and auditable
✅ Block Hash Randomness - Free, secure randomness using blockchain data
✅ No Central Authority - Fully decentralized operation
✅ Automatic Payouts - Winner gets 80%, admin gets 20%
✅ Public Blockchain - All transactions are transparent and verifiable
🎯 User Experience

✅ Modern UI/UX - Beautiful, responsive design with Tailwind CSS
✅ Real-time Updates - No page refresh needed for lottery updates
✅ Participant Visibility - See all participants and their entries
✅ Multiple Entry Support - Users can enter multiple times
✅ Wallet Integration - MetaMask and Web3 wallet support
🛠️ Technical Features

✅ TypeScript - Full type safety across the application
✅ Wagmi & Viem - Modern Ethereum development tools
✅ Hardhat - Professional smart contract development
✅ Sepolia Testnet - Deployed and tested on Ethereum testnet
✅ Auto-refresh - Real-time data updates after transactions
🚀 Quick Start

Prerequisites

Node.js 18+
npm or yarn
MetaMask or Web3 wallet
Sepolia ETH (get from faucets)
Installation

Clone the repository

git clone https://github.com/yourusername/dettery.git
cd dettery
Install dependencies

Install frontend dependencies

npm install

Install smart contract dependencies

cd contracts
npm install
cd ..
Environment Setup

Copy environment template

cp contracts/.env.example contracts/.env

Edit contracts/.env with your configuration

SEPOLIA_RPC_URL=https://ethereum-sepolia.publicnode.com
PRIVATE_KEY=your_private_key_here
ETHERSCAN_API_KEY=your_etherscan_api_key
Deploy Smart Contracts

cd contracts
npx hardhat compile
npx hardhat run scripts/deploy.ts --network sepolia
Update Frontend Configuration

// Update src/lib/config.ts with your deployed contract address
export const FACTORY_ADDRESS = 'your_deployed_contract_address';
Start the Application

npm run dev
Open in Browser

http://localhost:3000
📖 How It Works

  1. Create Lottery Pool

Set ticket price and maximum players
Deploy a new lottery contract
Lottery becomes available for participation

  1. Participate

Connect your Web3 wallet
Pay the ticket price to enter
Multiple entries allowed per user

  1. Winner Selection

When lottery reaches maximum players
System waits 2 blocks for fair randomness
Block hash randomness selects winner automatically

  1. Payouts

Winner receives 80% of total pool
Admin receives 20% fee
All transactions are automatic and transparent
🏗️ Architecture

Smart Contracts

contracts/
├── Lottery.sol # Individual lottery logic
├── LotteryFactory.sol # Factory for creating lotteries
└── scripts/
└── deploy.ts # Deployment script
Frontend

src/
├── app/ # Next.js App Router
├── components/ # React components
│ ├── ConnectWallet.tsx
│ ├── CreateLottery.tsx
│ ├── LotteryCard.tsx
│ └── LotteryList.tsx
└── lib/
└── config.ts # Contract addresses and ABIs
🔧 Configuration

Environment Variables

Create contracts/.env:

SEPOLIA_RPC_URL=https://ethereum-sepolia.publicnode.com
PRIVATE_KEY=your_private_key_here
ETHERSCAN_API_KEY=your_etherscan_api_key
Contract Addresses

Update src/lib/config.ts:

export const FACTORY_ADDRESS = '0xDE22C7fF7Ac8C7645AfB673a4Ea7087705FE94Ce';
🧪 Testing

Smart Contract Tests

cd contracts
npx hardhat test
Frontend Testing

npm run test
Manual Testing

Connect MetaMask to Sepolia testnet
Get Sepolia ETH from faucets
Create a lottery pool
Participate with multiple wallets
Test winner selection and payouts
📊 Smart Contract Details

Lottery Contract

contract Lottery {
// Core state variables
uint256 public immutable i_ticketPrice;
uint256 public immutable i_maxPlayers;
address payable public immutable i_admin;

// Lottery state
enum LotteryState { OPEN, CALCULATING_WINNER, CLOSED }
LotteryState private s_lotteryState;

// Participants and winner
address payable[] public s_players;
address public s_winner;

// Randomness
uint256 public s_commitBlock;
uint256 public s_revealBlock;
Enter fullscreen mode Exit fullscreen mode

}
Key Functions

enter() - Join the lottery by paying ticket price
pickWinner() - Select winner using block hash randomness
getPlayers() - Get list of all participants
getLotteryState() - Get current lottery state
🔒 Security Features

Randomness

Uses blockhash(), block.timestamp, and block.prevrandao
Commits to randomness block, reveals after 2 blocks
Prevents manipulation and ensures fairness
Access Control

Only lottery participants can trigger winner selection
Admin cannot manipulate results
All functions are public and auditable
Transparency

All lottery data is public
Contract source code is verified
All transactions are on-chain
🌐 Deployment

Sepolia Testnet (Current)

Factory Contract: 0xDE22C7fF7Ac8C7645AfB673a4Ea7087705FE94Ce
Network: Ethereum Sepolia
RPC: https://ethereum-sepolia.publicnode.com
Mainnet Deployment

Update environment variables
Deploy to mainnet
Verify contracts on Etherscan
Update frontend configuration
🤝 Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

Development Setup

Fork the repository
Create a feature branch
Make your changes
Add tests if applicable
Submit a pull request
📝 License

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

🆘 Support

Issues: GitHub Issues
Discussions: GitHub Discussions
Documentation: Wiki
🙏 Acknowledgments

Hardhat - Smart contract development framework
Next.js - React framework
Wagmi - React hooks for Ethereum
Viem - TypeScript interface for Ethereum
Tailwind CSS - CSS framework
📈 Roadmap

Mainnet deployment
Mobile app (React Native)
Additional randomness providers
Lottery categories and themes
Governance token
Multi-chain support

Comments 1 total

  • chovy
    chovyFeb 17, 2026

    Cool project. The Chainlink VRF approach for randomness is smart — that's basically the gold standard for on-chain fairness right now.

    One thing I've been thinking about with lottery dapps: the UX gap between "provably fair" and "feels fair" to users. You can verify the math, but most players won't. The real differentiator ends up being transparency of the pot and payout speed.

    We took a slightly different angle with cryptoshot.space — more of a jackpot mechanic where the pot grows visibly and the smart contract handles payouts automatically. Similar Ethereum + Sepolia stack. The hardest part wasn't the contract logic, it was making the frontend feel exciting enough that people actually want to participate.

    How's the gas cost working out on Sepolia vs what you'd expect on mainnet? That's always the elephant in the room with lottery contracts — the entry fee needs to justify the tx cost.

Add comment