Skip to content

Conversation

@yuviji
Copy link

@yuviji yuviji commented Nov 23, 2025

Pyth Examples Contribution

Type of Contribution

  • New Example Project (Adding a new example to demonstrate Pyth integration)
  • Bug Fix (Fixing an issue in existing examples)
  • Documentation Update (Improving README, comments, or guides)
  • Enhancement (Improving existing functionality or adding features)
  • Hackathon Submission (Submitting a project from a hackathon)

Project Information

Project/Example Name: 0xSlither

Pyth Product Used:

  • Pyth Price Feeds
  • Pyth Entropy
  • Multiple Products
  • Other: ___________

Blockchain/Platform:

  • Ethereum/EVM (Base Sepolia + Saga Chainlet)
  • Solana
  • Aptos
  • Sui
  • Fuel
  • Starknet
  • TON
  • Other: ___________

Description

What does this contribution do?

0xSlither is a real-time multiplayer snake game with a complete on-chain economy and provably fair randomness. Players stake tokens to enter matches, compete in real-time gameplay, and winners collect the stakes of players they eliminate. The game features smooth 60 FPS rendering, authoritative server architecture running on decentralized compute (Fluence CPU), and all game outcomes are stored permanently on-chain.

Key Features:

  • Real-time Multiplayer: Authoritative 20 TPS game server with WebSocket communication and ultra-smooth 60 FPS client rendering
  • Stake-to-Play Economy: Players stake SSS tokens to enter, winners collect 100% of eliminated players' stakes, with tap-out functionality for safe exits
  • Provably Fair Randomness: Uses Pyth Entropy for cryptographically verifiable random generation of spawn positions, snake colors, and pellet layouts
  • On-Chain Leaderboard: Top 10 players tracked permanently on the Saga blockchain
  • Decentralized Infrastructure: Game server runs on Fluence CPU (decentralized compute), frontend hosted on Vercel

How does it integrate with Pyth?

0xSlither uses Pyth Entropy in a cross-chain architecture to provide cryptographically secure, verifiable randomness for all match-critical random values:

Cross-Chain Architecture:

  1. Base Sepolia (Entropy Chain): Hosts the Pyth Entropy oracle via EntropyOracle.sol contract
  2. Saga Chainlet (Game Chain): Hosts the main game contract (StakeArena.sol) with dedicated EVM L1 for game economy

Integration Flow:

Server → EntropyOracle (Base Sepolia) → Request entropy
         ↓
Pyth Network reveals randomness (10-30s)
         ↓
Server → Retrieve seed from Base Sepolia
         ↓
Server → Commit seed hash to StakeArena (Saga)
         ↓
Generate deterministic game elements:
  • Player spawn positions: keccak256(seed, "spawn", playerAddress, retryCount)
  • Snake colors: keccak256(seed, "color", playerAddress)  
  • Pellet field layout: keccak256(seed, "pellets")
  • Map pattern type: keccak256(seed, "map")

Key Implementation:

  • EntropyBridgeService.ts: Handles cross-chain entropy requests and polling
  • EntropyOracle.sol: Consumes Pyth Entropy on Base Sepolia and stores seeds per match
  • DeterministicRNG.ts: Converts the entropy seed into reproducible random values
  • StakeArena.sol: Stores entropy seed hash for on-chain verification

Verification:

  • Match seed hash committed on-chain: StakeArena.entropySeedByMatch[matchId]
  • Entropy request ID stored: EntropyOracle.entropyRequestIdByMatch[matchId]
  • Fair match badge displayed in-game with verifiable match ID

What problem does it solve or demonstrate?

Problems Solved:

  1. Fair Randomness in Competitive Gaming: Traditional online games use server-side RNG that players must trust. 0xSlither demonstrates how Pyth Entropy provides cryptographically verifiable randomness, ensuring no player has an unfair spawn position or advantage.

  2. Cross-Chain Randomness Architecture: Shows how to bridge Pyth Entropy between chains - requesting entropy on Base Sepolia (where Pyth is available) and using it on Saga Chainlet (the game chain), demonstrating real-world multi-chain integration patterns.

  3. Deterministic Game Replay: By using a single verifiable seed, all game-critical random elements can be reproduced, enabling match replay, dispute resolution, and tournament verification.

  4. On-Chain Gaming Economy with Verifiable Fairness: Combines real-time gameplay with blockchain-based staking economy, where fairness is provable through Pyth Entropy - crucial for games involving real value.

Use Cases Demonstrated:

  • Gaming with verifiable fair RNG
  • Cross-chain oracle integration patterns
  • Deterministic randomness for reproducibility
  • High-frequency game state with low-frequency blockchain verification
  • Real-time multiplayer with authoritative server + blockchain economy

Directory Structure (for new examples)

entropy/0xSlither/
├── client/              # Frontend application (Vite + TypeScript)
│   └── src/
│       ├── main.ts              # Entry point
│       ├── Game.ts              # Game state management
│       ├── Renderer.ts          # Canvas rendering (60 FPS)
│       ├── Camera.ts            # Smooth camera system
│       ├── InputHandler.ts      # Mouse controls
│       ├── WalletService.ts     # Web3 wallet integration
│       └── UI.ts                # UI components
├── server/              # Game server (Node.js + TypeScript)
│   └── src/
│       ├── index.ts             # WebSocket server
│       ├── GameServer.ts        # Main game loop (20 TPS)
│       ├── Snake.ts             # Snake entity
│       ├── Pellet.ts            # Pellet management
│       ├── CollisionDetection.ts # Physics
│       ├── BlockchainService.ts  # Saga Web3 integration
│       ├── EntropyBridgeService.ts # Pyth cross-chain entropy
│       ├── DeterministicRNG.ts   # Seeded RNG from entropy
│       └── Leaderboard.ts       # Rankings
├── contracts/           # Smart contracts (Solidity)
│   ├── contracts/
│   │   ├── StakeArena.sol       # Main game contract (Saga)
│   │   ├── EntropyOracle.sol    # Pyth Entropy consumer (Base Sepolia)
│   │   └── GameToken.sol        # ERC20 token (optional)
│   └── scripts/
│       ├── deployStakeArena.ts  # Deploy to Saga
│       ├── deployEntropyOracle.ts # Deploy to Base Sepolia
│       ├── updateServer.ts      # Authorize server
│       └── getLeaderboard.ts    # Query rankings
├── shared/              # Shared TypeScript types
│   ├── constants.ts     # Game configuration
│   ├── types.ts         # Entity definitions
│   └── protocol.ts      # Network messages
├── README.md            # Project documentation
├── PROJECT_OVERVIEW.md  # Technical overview
└── package.json         # Monorepo workspace config

Testing & Verification

How to Test This Contribution

This project is fully deployed and live in production. You can test it immediately or run it locally.

Option 1: Test Live Deployment (Recommended)

No setup required! Just visit the live game:

🎮 https://0xslither.vercel.app

  1. Open the game in your browser
  2. Connect MetaMask wallet (optional, for staking features)
  3. Enter your name and click "Play" (free play available)
  4. Control your snake with mouse movement
  5. Eat pellets to grow, avoid other snakes
  6. View the "Fair Match Badge" showing Pyth Entropy verification

To test with staking:

  • Add Saga Chainlet network to MetaMask (auto-configured)
  • Get SSS tokens from Saga Faucet
  • Stake SSS tokens to enter competitive matches
  • View on-chain leaderboard

Option 2: Run Locally

Prerequisites

npm install -g pnpm
  • MetaMask: Browser extension (for blockchain features)
  • Test tokens:

Setup & Run Instructions

# 1. Clone the repository
git clone https://github.com/yourusername/0xSlither.git
cd 0xSlither

# 2. Install dependencies (installs all workspaces)
pnpm install

# 3. Run without blockchain (local game only)
pnpm run dev
# This starts:
# - Game server on port 8080 (WebSocket)
# - Web client on port 3000 (HTTP)
# Open http://localhost:3000 to play

# 4. (Optional) Run with blockchain integration
# Copy and configure environment variables
cd contracts
cp .env.example .env
# Edit .env with your deployer private key

# Deploy contracts
pnpm run deploy:entropy   # Deploy EntropyOracle to Base Sepolia
pnpm run deploy:saga      # Deploy StakeArena to Saga Chainlet

# Configure server
cd ../server
cat > .env << EOF
SERVER_PRIVATE_KEY=0x...              # Your server wallet key
STAKE_ARENA_ADDRESS=0x...             # From deploy:saga output
ENTROPY_ORACLE_ADDRESS=0x...          # From deploy:entropy output
BASE_SEPOLIA_RPC_URL=https://sepolia.base.org
SAGA_CHAINLET_RPC_URL=https://slither-2763767854157000-1.jsonrpc.sagarpc.io
ENABLE_BLOCKCHAIN=true
EOF

# Configure client
cd ../client
cat > .env << EOF
VITE_BLOCKCHAIN_ENABLED=true
VITE_STAKE_ARENA_ADDRESS=0x...
VITE_SAGA_CHAINLET_RPC_URL=https://slither-2763767854157000-1.jsonrpc.sagarpc.io
VITE_SAGA_CHAIN_ID=2763767854157000
EOF

# Authorize server wallet
cd ../contracts
pnpm run update:server

# Start game with blockchain
cd ..
pnpm run dev

Test Multiplayer

Open multiple browser tabs to http://localhost:3000 (or the live URL) - each tab runs as a separate player!

Deployment Information (if applicable)

Production Deployment:

Component Platform URL/Details
Frontend Vercel 0xslither.vercel.app
Game Server Fluence CPU Decentralized compute platform
StakeArena Contract Saga Chainlet View on Explorer
EntropyOracle Contract Base Sepolia 0x662371163C3797b66ab80dCB592761718537F492

Networks:

  • Base Sepolia (Entropy Chain)

  • Saga Chainlet (Game Chain)

    • RPC: https://slither-2763767854157000-1.jsonrpc.sagarpc.io
    • Chain ID: 2763767854157000
    • Explorer: Saga Explorer
    • Purpose: Hosts game economy and staking

Contract Addresses:

  • EntropyOracle (Base Sepolia): 0x662371163C3797b66ab80dCB592761718537F492
  • StakeArena (Saga): See Saga Explorer

Demo URL: https://0xslither.vercel.app

Checklist

Code Quality

  • Code follows existing patterns in the repository
  • Proper error handling implemented (try-catch, fallback RNG)
  • No hardcoded values (uses environment variables for all config)
  • TypeScript with strict type checking
  • Clean architecture with separation of concerns

Testing

  • Tested locally and works as expected
  • All existing functionality still works (no breaking changes)
  • Tested with multiple concurrent players (10+ simultaneous)
  • Tested cross-chain entropy flow (Base → Saga)
  • Tested with and without blockchain integration
  • Deployed and running in production

Documentation

  • Comprehensive README.md with setup instructions
  • PROJECT_OVERVIEW.md with technical details
  • Contract documentation in contracts/README.md
  • Inline code comments explaining Pyth integration
  • Architecture diagrams for entropy flow

Pyth Integration Specifics

  • Pyth Entropy properly integrated via EntropyOracle contract
  • Cross-chain architecture implemented (Base ↔ Saga)
  • Deterministic RNG from entropy seed
  • On-chain verification enabled (seed hash committed)
  • Fallback RNG for graceful degradation
  • Entropy fee handling with balance checks
  • Request ID tracking for auditability

Additional Context

Built for ETHGlobal Buenos Aires 2025 🇦🇷

This project was built as part of ETHGlobal Buenos Aires hackathon, demonstrating innovative use of Pyth Entropy for gaming applications.

Key Technical Achievements

  1. Cross-Chain Entropy: First multiplayer game demonstrating Pyth Entropy bridging between L2 (Base Sepolia) and L1 (Saga)
  2. Deterministic Gameplay: Entire match can be replayed from a single entropy seed
  3. Production-Ready: Fully deployed with decentralized server infrastructure
  4. Real-Time + Blockchain: Combines 20 TPS game server with on-chain economy
  5. Graceful Degradation: Falls back to cryptographically secure RNG if Pyth unavailable

Architecture Highlights

Why Cross-Chain?

  • Saga Chainlet provides dedicated chain with recycled gas fees (perfect for gaming)
  • Base Sepolia has Pyth Entropy testnet deployment
  • Server bridges entropy between chains, demonstrating real-world multi-chain pattern

Performance:

  • Server: 20 TPS authoritative game loop
  • Client: 60 FPS rendering with interpolation
  • Supports 10-20+ concurrent players
  • <50ms typical latency (local), <200ms acceptable

Related Issues

Part of Pyth Entropy adoption effort for gaming use cases.

Screenshots/Demo

Live Demo: https://0xslither.vercel.app

On-Chain Verification:

In-Game Features:

  • Fair Match Badge displays Match ID and Entropy verification status
  • Leaderboard shows top 10 players with on-chain scores
  • Real-time stake tracking
  • Smooth 60 FPS gameplay with verifiable randomness

Notes for Reviewers

  1. Live & Testable: The entire project is deployed and running at 0xslither.vercel.app - you can test it immediately without any setup!

  2. Pyth Entropy Focus: The key integration is in:

    • server/src/EntropyBridgeService.ts - Cross-chain entropy bridge
    • contracts/contracts/EntropyOracle.sol - Pyth Entropy consumer
    • server/src/DeterministicRNG.ts - Seed-based RNG
    • server/src/GameServer.ts - Integration with game loop
  3. Fallback Behavior: The game works without Pyth Entropy (uses crypto.randomBytes) but displays verification badge when Pyth is used, demonstrating production-ready error handling.

  4. Cross-Chain Pattern: This demonstrates a reusable pattern for bringing Pyth Entropy to chains that don't have direct integration yet.

  5. Complete Stack: This is a full production application, not just a proof-of-concept - includes frontend, backend, contracts, and deployment infrastructure.

Tech Stack

Frontend:

  • TypeScript + Vite
  • Canvas 2D rendering
  • ethers.js v6
  • Hosted on Vercel

Backend:

  • Node.js + TypeScript
  • WebSocket (ws library)
  • ethers.js v6
  • Hosted on Fluence CPU

Blockchain:

  • Solidity 0.8.20
  • Hardhat development
  • OpenZeppelin contracts
  • Pyth Entropy SDK

Future Enhancements

  • Mobile touch controls
  • Audio and sound effects
  • NFT snake skins (ERC721)
  • Tournament mode with brackets
  • Achievement system with NFT badges
  • Mainnet deployment

Links & Resources


Thank you for considering 0xSlither for Pyth Examples!

This project demonstrates real-world Pyth Entropy integration in a production gaming environment, showcasing cross-chain architecture, deterministic randomness, and verifiable fairness.

@yuviji yuviji changed the title add 0xslither add 0xslither: Pyth Entropy @ ETHGlobal BA 2025 Nov 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant