Skip to main content

Program

This page documents the Private Raffle program’s instructions and account structures.

Account Structures

Lottery

The main raffle account:

Ticket

Each player’s ticket:

Instructions

create_lottery

Creates a new raffle.
Accounts:

buy_ticket

Purchase a ticket with an encrypted guess.
What it does:
  1. Transfers ticket price to vault
  2. Creates encrypted handle from guess
  3. Stores ticket with encrypted guess
  4. Allows buyer to decrypt their own guess
Accounts:

draw_winner

Authority sets the encrypted winning number and closes the raffle.
What it does:
  1. Verifies caller is authority
  2. Closes the raffle (is_open = false)
  3. Stores encrypted winning number

check_winner

Compares a ticket’s guess against the winning number (encrypted comparison).
What it does:
  1. Uses e_eq to compare guess_handle with winning_number_handle
  2. Stores encrypted boolean result in is_winner_handle
  3. Allows ticket owner to decrypt the result
Key encrypted operation:

claim_prize

Calculates the encrypted prize amount based on win/loss status.
What it does:
  1. Creates encrypted prize amount (vault balance)
  2. Creates encrypted zero
  3. Uses e_select: if winner, get prize; else get 0
  4. Stores encrypted prize amount
  5. Marks ticket as claimed
Key encrypted operation:

withdraw_prize

Winner withdraws their prize with on-chain signature verification.
What it does:
  1. Verifies ticket owner and claimed status
  2. Verifies Ed25519 signature on-chain (proves decryption is valid)
  3. Parses plaintext to get prize amount
  4. Rejects if prize is 0 (not a winner)
  5. Transfers SOL from vault to winner
Key verification:

Error Codes


PDA Seeds

AccountSeeds
Lottery["lottery", lottery_id]
Vault["vault", lottery_pubkey]
Ticket["ticket", lottery_pubkey, buyer_pubkey]

Next Steps

See Client Integration for TypeScript usage examples.