Skip to content

YASH-YADAV-dynamo/Dino.sol

Repository files navigation

DINO.sol - A Solana-Powered Dino Runner Game

DINO.sol is an on-chain game built on Solana where players pay SOL to play and earn rewards based on their performance. The game features a classic dino runner mechanic with blockchain integration for payments and rewards.

🎮 Game Overview

Gameplay Mechanics

  • Character: A dinosaur that runs and jumps over obstacles
  • Obstacles: Black rectangular blocks spawn randomly on the ground
  • Controls: Press SPACE or click to make the dino jump
  • Scoring: Each obstacle passed increases your score
  • Difficulty: Game speed gradually increases over time

Visual Design

  • Background: Light green sky (#ccffcc)
  • Ground: Black surface where the dino runs and jumps
  • Theme: Minimalist black and white design with a clean, retro aesthetic

⛓️ Solana Architecture

Payment System

Pay-to-Play Model:

  • Players must pay 1 SOL (devnet) before each game session
  • Payment is sent from the player's wallet to the game treasury via SystemProgram.transfer
  • The payment is processed client-side using the Solana Wallet Adapter
  • Once payment is confirmed, the game unlocks

Flow:

  1. User connects wallet (Phantom, Solflare, etc.)
  2. User navigates to /play
  3. SolPaymentWrapper checks SOL balance
  4. If sufficient, user pays 1 SOL to treasury
  5. Game unlocks and player can start playing

Reward System

Score-Based Rewards:

  • Reward formula: Score ÷ 5 = SOL Reward
  • Example: Score of 10 = 2 SOL reward, Score of 25 = 5 SOL reward
  • Rewards are automatically sent from the treasury wallet to the player's wallet

Architecture:

  • Frontend: Game component calls /api/reward endpoint when game ends
  • Backend: Server-side API route handles treasury signing (private key never exposed to client)
  • Treasury Wallet: Holds SOL for rewards and faucet operations
  • Transaction: Uses SystemProgram.transfer to send SOL from treasury to player

Security:

  • Treasury private key is stored server-side only (in environment variables)
  • Client never has access to treasury signing capabilities
  • All reward transactions are signed server-side using the treasury keypair

Faucet System

SOL Faucet:

  • Located at /buy-worm route
  • Provides free devnet SOL to players who need it
  • Daily limit: 0.25 SOL per wallet address
  • Uses the same treasury wallet to distribute SOL

Technical Stack

Frontend:

  • Next.js 16 (App Router) - React framework
  • Phaser 3 - Game engine for the dino runner
  • Solana Web3.js - Blockchain interactions
  • @solana/wallet-adapter-react - Wallet connection and transaction signing

Backend:

  • Next.js API Routes - Server-side endpoints for rewards and faucet
  • Solana Web3.js - Server-side transaction signing
  • Treasury Keypair - Server-managed wallet for automated payments

Key Components:

  • components/SimpleFlappyGame.tsx - Main game logic and Phaser scene
  • components/SolPaymentWrapper.tsx - Payment gate before game access
  • app/api/reward/route.ts - Server-side reward distribution
  • app/api/sol-faucet/route.ts - Server-side SOL faucet

🚀 Getting Started

Install Dependencies

npm install

Run Development Server

npm run dev

Open http://localhost:3000 to play the game.

🔄 Game Flow

  1. Splash Screen → First-time users see an intro story
  2. Home Page → Connect wallet, view game info
  3. Play Route → Pay 1 SOL to unlock game
  4. Gameplay → Jump over blocks, increase score
  5. Game Over → Calculate reward (score/5), send SOL from treasury
  6. Reward Modal → Display earned SOL amount
  7. Redirect → Return to home page

🔐 Security Considerations

  • Treasury Key Management: Private keys are stored server-side only, never exposed to the client
  • Transaction Signing: All treasury-signed transactions happen on the server via API routes
  • Wallet Integration: Client-side wallet adapter handles user transactions securely
  • Network: Currently configured for Solana devnet (testnet SOL only)

📚 Learn More

Solana Development:

Game Development:

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors