All projects

Crystal Chain

First stake-to-play lottery with Chainlink VRF & CRE for provably fair, fully automated gaming

Prediction Markets DeFi & Tokenization World

What it is

Crystal Chain is a next-generation decentralized lottery platform that revolutionizes traditional gaming by combining DeFi staking mechanisms with provably fair gameplay. Unlike conventional lotteries where players are mere ticket buyers, Crystal Chain transforms participants into stakeholders through our innovative stake-to-play model.

The Problem We Solve:
Traditional lotteries suffer from three critical issues:

  1. Opacity: Players can't verify if draws are truly random
  2. Centralization: Single operators control everything, creating trust issues
  3. Extractive Economics: Winners take all, losers get nothing, no community building

The global lottery market exceeds $100 billion annually, yet it operates on outdated, centralized systems with zero transparency and massive operator fees (often 50%+).

Our Solution:
Crystal Chain creates a DeFi-native lottery ecosystem with four key innovations:

  1. Stake-to-Play Model: Users must stake our platform token (PTK) to participate, creating a committed community of stakeholders, not just gamblers. This reduces spam, increases token utility, and aligns incentives.
  2. Provably Fair Randomness: Chainlink VRF v2.5 generates cryptographically secure random numbers with on-chain verification. Every draw is mathematically provable - no trust required.
  3. Fully Autonomous Operations: Chainlink CRE (Runtime Environment) workflows automate round endings, removing any centralized operator or manual intervention. The lottery runs itself.
  4. Loyalty Rewards System: Players who participate in 3+ consecutive rounds become eligible for gift distributions. Even if you don't win the main prize, loyalty is rewarded. This gamifies engagement and builds long-term community.

How It Works:

  1. New users claim a welcome bonus (200 PTK + 50 PTK auto-staked)
  2. Users stake more PTK to increase eligibility (minimum 10 PTK)
  3. Place bets by choosing 5 numbers from 1-49
  4. Chainlink CRE automatically triggers round ending after 5 minutes
  5. Chainlink VRF generates winning numbers (verifiable on-chain)
  6. Users claim winnings based on matches (2-5 matches pay 2x to 800x)
  7. Every round, 10 random loyal players receive bonus gifts

Impact & Innovation:

  • First stake-to-play lottery in existence - participants are stakeholders
  • Zero trust required - all randomness verifiable via Chainlink VRF
  • Zero manual operations - Chainlink CRE handles automation
  • Sustainable economics - 5% house edge, token burns, and creator rewards
  • Community-focused - consecutive play streaks unlock benefits
  • 90%+ gas savings - Deployable on L2s like Arbitrum for accessibility

Crystal Chain demonstrates how blockchain technology can transform traditional industries by replacing extractive, opaque systems with transparent, community-owned alternatives.

How it Works

Smart Contract Architecture (Solidity ^0.8.24):
We built a modular, production-ready smart contract system with clear separation of concerns:

  1. LotteryGameCore.sol: Core lottery logic
    a. Inherits from VRFConsumer for Chainlink VRF integration
    b. Implements betting, round management, and prize claiming
    c. Uses OpenZeppelin's ReentrancyGuard, AccessControl, and Pausable
    d. On-demand match calculation for gas optimization
    e. Tracks user stats including consecutive rounds
  2. PlatformToken.sol (PTK): ERC20 with DeFi features
    a. Staking mechanism with time-weighted rewards
    b. Burning capabilities (5% burn rate on certain operations)
    c. One-time bonus system for onboarding
    d. Authorized burner/transferor patterns for ecosystem integration
  3. LotteryGift.sol: Loyalty reward distribution
    a. Pseudo-random recipient selection using VRF entropy
    b. Gift reserve management
    c. Cooldown system to prevent gaming
    d. Creator sustainability model (creator gets rewards every round)
  4. LotteryAdmin.sol: Governance with timelock
    a. 24-hour timelock for critical operations
    b. Role-based access control
    c. Emergency pause functionality
    d. Treasury management
  5. VRFConsumer.sol: Abstract Chainlink VRF integration
    a. Implements VRFConsumerBaseV2Plus
    b. Request validation and callback handling
    c. Modular design for reusability
  6. LotteryRoundEndProxy.sol: Chainlink CRE integration
    a. Inherits from ReceiverTemplate
    b. Validates workflow reports from Chainlink forwarder
    c. Automatically triggers endRound() when workflow executes
    d. Decentralized automation without manual triggers

Chainlink Integration:

  • VRF v2.5: Used for generating winning lottery numbers
    • Subscription-based model with LINK payment
    • Request confirmations: 3 blocks
    • Gas limit: 500,000
    • Native payment enabled for flexibility
  • CRE Workflows: Automated round management
    • Monitors blockchain for round expiration
    • Sends reports to proxy contract
    • Triggers round endings without centralized operator
    • Forwarder validation ensures security

Frontend (React + TypeScript):

  • Built with Vite for fast development
  • Wagmi for Web3 interactions
  • Multi-chain support (Sepolia, Arbitrum Sepolia ready)
  • Responsive design with Tailwind CSS
  • Real-time updates using contract event subscriptions
  • Comprehensive error handling
  • Admin dashboard for privileged operations

Development Tools:

  • Foundry for smart contract development, testing, and deployment
  • The Graph (planned) for efficient historical data queries
  • OpenZeppelin contracts for security-audited base implementations
  • Chainlink Brownie Contracts for oracle integrations

Security Patterns:

  • Checks-Effects-Interactions pattern throughout
  • ReentrancyGuard on all state-changing functions
  • Input validation and sanity checks
  • Access control with OpenZeppelin's AccessControl
  • Emergency pause mechanism
  • Timelock for critical parameter changes

Gas Optimizations:

  • On-demand match calculation (only calculate when claiming)
  • Packed structs to minimize storage slots
  • Memory caching in loops
  • Events for historical data instead of excessive storage

Deployment:

  • Deployed on Sepolia testnet for testing
  • Multi-chain ready (Arbitrum support planned)
  • Verified contracts on Etherscan
  • Modular deployment scripts for easy redeployment

Links

Created by

  • Agwara Nnaemeka