Randomness Tutorial
Why Verifiable Randomness?
How It Works
1. COMMIT → 2. GENERATE → 3. REVEAL
Player Oracle Settlement
commits to generates Player reveals
slothash randomness and uses valueWhat You'll Build
Prerequisites
Key Concepts
Randomness Account
RandomnessAccountData
Slot-Based Freshness
Collateral on Commit (Critical!)
The On-Chain Program
Dependencies
Program Structure
Account Structures
Error Codes
The TypeScript Client
Setup
Create Randomness Account
Commit Phase
Reveal Phase
Retry Logic
Running the Example
1. Clone the Repository
2. Build the Program
3. Update Program ID
4. Deploy
5. Install Dependencies
6. Play!
Expected Output
Security Best Practices
1. Always Take Collateral at Commit Time
2. Validate Slot Freshness
3. Verify Randomness Account Reference
4. Check Randomness Not Already Revealed
Use Cases
Gaming & Gambling
NFT Minting
Lotteries
Fair Distribution
Advanced Topics
Reusing Randomness Accounts
Multiple Random Values
Next Steps
Last updated