Skip to content

The Prize Draw Pool is a decentralized lottery-style smart contract built on the Stacks blockchain using Clarity. It enables fair, transparent prize draws where participants purchase entries with STX tokens, and one randomly selected winner takes the entire accumulated prize pool.

Notifications You must be signed in to change notification settings

lukman-amuda/Prize-Draw-Pool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

Prize Draw Pool Smart Contract

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.

Overview

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.

Key Features

  • 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

Contract Constants

  • ERR-OVERFLOW: Error code u4 for overflow protection
  • contract-admin: The deployer address with administrative privileges

Data Variables

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

Public Functions

begin-draw()

Access: Admin only
Purpose: Starts a new draw round and enables entry purchases
Returns: (ok true) on success

purchase-entries(entry-count)

Access: Public
Parameters:

  • entry-count (uint): Number of entries to purchase Purpose: Allows users to buy entries for the current draw Payment: Automatically transfers entry-count * entry-fee STX to contract Returns: (ok true) on success

conclude-draw()

Access: Admin only
Purpose: Ends current draw, selects winner, transfers prize, and resets for next round
Returns: (ok true) on success

Read-Only Functions

get-draw-details()

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
}

get-champion(draw-number)

Parameters: draw-number (uint)
Returns: Winner details for specified round or none

{
  champion: principal,   // Winner's address
  prize: uint           // Prize amount won
}

get-entrant-entries(entrant, draw-number)

Parameters:

  • entrant (principal): Participant's address
  • draw-number (uint): Draw round number Returns: Number of entries purchased by participant in specified round

Usage Flow

  1. Admin starts draw: Call begin-draw() to enable participation
  2. Users buy entries: Call purchase-entries(n) with desired entry count
  3. Admin concludes draw: Call conclude-draw() to select winner and distribute prize
  4. Repeat: Process automatically resets for next round

Security Features

  • 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

Error Codes

  • u1: Unauthorized access (non-admin trying admin functions)
  • u2: Winner selection failed
  • u3: Maximum participants exceeded (50 limit)
  • u4: Integer overflow detected

Deployment Notes

  • 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

Limitations

  • 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

About

The Prize Draw Pool is a decentralized lottery-style smart contract built on the Stacks blockchain using Clarity. It enables fair, transparent prize draws where participants purchase entries with STX tokens, and one randomly selected winner takes the entire accumulated prize pool.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published