This project implements a simple on-chain raffle using the Move language on the Sui blockchain.
Users can buy tickets, and the raffle creator can close the raffle, randomly select a winner, and distribute the collected funds automatically.
- Each raffle is represented by a
Raffleobject - Users buy tickets by paying SUI
- Tickets are stored as indexed entries in a table
- When the raffle is closed, a winner is selected randomly
- The total pot is split between:
- the raffle owner
- the winner
This project is for educational purposes only.
The Raffle struct stores:
- Raffle metadata (title, owner)
- Ticket price
- Number of tickets sold
- A table mapping ticket indices to buyer addresses
- The accumulated pot stored as
Balance<SUI> - The winning ticket index (after the raffle ends)
Tickets are represented only by an index and the buyer address.
No Ticket NFT or object is created to keep the implementation simple and cost-efficient.
- The creator deploys a raffle
- Users buy tickets by sending SUI
- The collected value is added to the raffle pot
- The creator closes the raffle
- A random ticket index is selected
- The pot is distributed to the owner, and winner
- The random number generation used is not secure for production
- The raffle must be closed manually by the owner
- No refund mechanism is implemented
- This project is intended for learning purposes only
- Secure randomness (commitβreveal, VRF, or beacon-based RNG)
- Admin capability for governance
- Ticket NFTs for transferability
- Automatic raffle closing based on time or epoch
Publish your Raffle Move package to the Sui network:
sui client publishThis will deploy the package and give you the PACKAGE_ID for the next steps.
Create a new raffle with a title and ticket price:
sui client call --package [PACKAGE_ID] --module raffle --function create --args [RAFFLE_TITLE] [TICKET_PRICE_MINT]- RAFFLE_TITLE: Name of your raffle (string)
- TICKET_PRICE_MINT: Ticket price in MIST (u64)
Users can buy tickets for the raffle using a SUI coin:
sui client call --package [PACKAGE_ID] --module raffle --function buy_ticket --args [RAFFLE_ID] [COIN_ID] --gas [GAS_COIN_ID] --gas-budget 10000000- RAFFLE_ID: ID of the raffle object
- COIN_ID: SUI coin used to pay for the ticket
- GAS_COIN_ID: SUI coin used to pay for gas (must be different from COIN_ID)
The raffle owner can close the raffle, draw a winner, and distribute the pot:
sui client call --package [PACKAGE_ID] --module raffle --function end --args [RAFFLE_ID] [RANDOM] --gas [GAS_COIN_ID] --gas-budget 10000000- RAFFLE_ID: ID of the raffle object
- RANDOM: Sui Random singleton (0x000000000000000000000000000000000000008)
- GAS_COIN_ID: SUI coin used to pay for gas
This project was developed as part of a sui bootcamp and is not production-ready.
It is intended to demonstrate basic concepts of Move and Sui.