Inspiration
The inspiration for Luck3 came from my dissatisfaction with the opacity of real-world lotteries. As someone deeply interested in decentralized finance (DeFi) and Web3 applications, I wanted to create a project that demonstrates the power of transparency, on-chain randomness, and fair competition. Traditional lotteries often suffer from trust issues and opaque operations—Starknet's scalability and security provided the perfect platform to build something better.
The simplicity and excitement of number-guessing games and daily draws particularly inspired me. My idea was to create a lottery that anyone could participate in, using Starknet's native STRK token with extremely low barriers. The project name "Luck3" means Luck on Web3, expressing fair luck and transparent drawing experiences.
What it does
Luck3 is a decentralized lottery application built on the Starknet blockchain. Players can purchase lottery tickets by guessing numbers between 10-99, with each ticket costing 1 STRK token. Winners share the prize pool based on correct guesses, with all transactions and draws happening transparently on-chain. Features include daily fair draws every 5 minutes using blockchain-based randomness, secure and transparent operations with Cairo smart contracts, instant STRK rewards for winners, low entry cost, simple gameplay, real-time stats, and seamless wallet integration.
How we built it
The project is a full-stack decentralized application consisting of three main components:
Smart Contract Layer
I first built the Cairo smart contract using Starknet Foundry (Scarb). The contract handles the following functions:
- Ticket purchases using STRK tokens
- Winner selection using block timestamp-based randomness
- Reward claiming, with a 10% platform fee deducted first
The contract was written in Cairo and compiled and tested using snforge. Main functions include buy_ticket, draw_winner, and claim_reward.
Frontend Layer
The React frontend was built with TypeScript and uses Vite for fast development. I integrated Starknet React for wallet connections and contract interactions. UI features:
- Real-time lottery statistics
- Animated backgrounds using CSS
- Responsive design with Tailwind CSS
- State management with custom hooks
Components are organized into pages (Home, Lottery, History) and reusable elements such as connect buttons and loading areas.
Development Workflow
- Planning: Define requirements and architecture
- Contract Development: Write and test Cairo code
- Frontend Development: Build React components and integrate blockchain calls
- Testing: Unit tests for contracts, manual testing for frontend
- Deployment: Configure for Starknet Sepolia testnet
- Release: Deploy the contract to Starknet mainnet and provide public links for everyone to experience
The build process includes scarb build for contracts and pnpm run build for the frontend.
Challenges we ran into
Building on Starknet presented some unique challenges. Cairo's syntax is different from Solidity, with a steep learning curve—especially understanding implicit arguments and its abandonment of loops in favor of recursion.
Implementing fair randomness was a major challenge. Block timestamps are not truly random, so I had to balance security and practicality. The solution combined timestamp and round number, but this could potentially be exploited by miners. Future iterations might incorporate VRF (Verifiable Random Function) for better randomness.
Gas optimization was another hurdle. Cairo contracts require careful design to minimize computational steps. I spent considerable time refactoring functions to reduce gas costs, particularly in the winner selection logic.
Frontend integration was also tricky. Handling asynchronous blockchain calls, managing wallet connections, and providing real-time updates required robust error handling and state management. The 5-minute round cycles meant implementing polling mechanisms that didn't overwhelm the network.
Finally, testing on the testnet revealed edge cases like concurrent ticket purchases and round transitions. Debugging on-chain transactions was challenging without traditional logging, requiring careful use of events and off-chain simulation.
Accomplishments that we're proud of
We're proud of successfully building and deploying a fully functional decentralized lottery on Starknet, demonstrating transparent on-chain operations that eliminate trust issues common in traditional lotteries. The project achieved low gas costs, fair randomness implementation, and a user-friendly interface that makes blockchain gaming accessible. We've created a system where every transaction is verifiable, rewards are instant, and the platform maintains only a 10% fee while ensuring equitable prize distribution.
What we learned
Through this project, I gained a deeper understanding of Starknet's ecosystem and Cairo programming. I learned how to implement timestamp-based randomness for fair draws, ensuring the system remains unpredictable yet verifiable.
In terms of mathematics, I explored probability distributions in lottery systems. For example, if the number range is from 10 to 99 (90 possible outcomes), then the probability of winning a single ticket is:
[ P(\text{win}) = \frac{1}{90} \approx 0.0111 ]
This helped me understand the risk-reward dynamics and design the prize distribution system, where winners split 90% of the prize pool equally.
I also learned how to integrate the frontend with blockchain wallets, state management in React, and the challenges of building responsive UIs for Web3 applications. This project made me realize the importance of comprehensive testing, including unit tests for contracts and integration tests for the full stack.
What's next for Luck3
Future plans for Luck3 include integrating Verifiable Random Functions (VRF) for truly unpredictable randomness, expanding to multi-chain support beyond Starknet, implementing advanced features like jackpot multipliers and referral systems, and enhancing the UI with more interactive elements and mobile optimization. We also plan to conduct security audits and explore partnerships for real-world adoption.
Built With
- cairo
- react
- tailwindcss
- typescript
- vite


Log in or sign up for Devpost to join the conversation.