A decentralized prize draw system built on the Stacks blockchain using Clarity smart contracts. This contract enables fair and transparent prize draws where participants can purchase entries and one random winner takes the entire prize pool.
The Prize Draw Pool contract allows users to participate in recurring prize draws by purchasing entries with STX tokens. Each draw cycle accumulates funds from all participants, and at the end of each round, one participant is randomly selected to win the entire prize pool.
- Decentralized Random Selection: Uses block timestamps and internal seed for winner selection
- Overflow Protection: Built-in safeguards against integer overflow attacks
- Multi-Entry Support: Participants can purchase multiple entries to increase winning chances
- Administrative Controls: Contract admin can start and conclude draw rounds
- Transparent History: All past winners and prizes are permanently recorded on-chain
- ERR-OVERFLOW: Error code
u4for overflow protection - contract-admin: The deployer address with administrative privileges
| Variable | Type | Default | Description |
|---|---|---|---|
draw-round |
uint | 0 | Current draw round number |
pool-funds |
uint | 0 | Total STX accumulated in current draw |
min-entrants |
uint | 3 | Minimum participants required |
entry-fee |
uint | 100 | Cost per entry in microSTX |
draw-active |
bool | false | Whether draw is accepting entries |
randomness-seed |
uint | 0 | Internal seed for random number generation |
Access: Admin only
Purpose: Starts a new draw round and enables entry purchases
Returns: (ok true) on success
Access: Public
Parameters:
entry-count(uint): Number of entries to purchase Purpose: Allows users to buy entries for the current draw Payment: Automatically transfersentry-count * entry-feeSTX to contract Returns:(ok true)on success
Access: Admin only
Purpose: Ends current draw, selects winner, transfers prize, and resets for next round
Returns: (ok true) on success
Returns current draw information:
{
draw-round: uint, // Current round number
pool-balance: uint, // Total STX in pool
is-active: bool, // Whether accepting entries
entry-cost: uint, // Cost per entry
minimum-entrants: uint // Min participants needed
}Parameters: draw-number (uint)
Returns: Winner details for specified round or none
{
champion: principal, // Winner's address
prize: uint // Prize amount won
}Parameters:
entrant(principal): Participant's addressdraw-number(uint): Draw round number Returns: Number of entries purchased by participant in specified round
- Admin starts draw: Call
begin-draw()to enable participation - Users buy entries: Call
purchase-entries(n)with desired entry count - Admin concludes draw: Call
conclude-draw()to select winner and distribute prize - Repeat: Process automatically resets for next round
- Overflow Protection: All arithmetic operations are protected against integer overflow
- Access Control: Critical functions restricted to contract admin
- Safe Transfers: Uses Stacks native transfer functions with error handling
- Participant Limits: Maximum 50 unique participants per draw round
u1: Unauthorized access (non-admin trying admin functions)u2: Winner selection failedu3: Maximum participants exceeded (50 limit)u4: Integer overflow detected
- Deploy with sufficient STX for gas fees
- Admin address is set to deployer's address (
tx-sender) - Entry fee is set to 100 microSTX (0.0001 STX) by default
- Minimum 3 participants required per round
- Maximum 50 unique participants per draw
- Randomness depends on block timestamps (not cryptographically secure)
- Admin has full control over draw timing
- No automatic draw conclusion mechanism