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
- Create Lottery Pool
Set ticket price and maximum players
Deploy a new lottery contract
Lottery becomes available for participation
- Participate
Connect your Web3 wallet
Pay the ticket price to enter
Multiple entries allowed per user
- Winner Selection
When lottery reaches maximum players
System waits 2 blocks for fair randomness
Block hash randomness selects winner automatically
- 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;
}
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
Top comments (0)