A free-to-play decentralized Rock Paper Scissors game with AI and multiplayer modes. Multi-chain support (Celo + Base). Built with scaffold-eth-2.
Available on Farcaster at: https://farcaster.xyz/miniapps/e7MMsOYu-YxM/rps-onchain
- Wallet Authentication: Reown AppKit + Wagmi integration
- Human Verification: Self Protocol onchain identity verification
- Free to Play: No betting, just pure fun
- Single Player: Play against AI instantly
- Multiplayer: Create/join rooms with 6-character codes
- Unlimited Rematches: Play again and again with friends
- Match History: Persistent storage via Turso + IPFS backup
- Blockchain Verification: Optional on-chain match publishing
- On-Chain Matches: View all published matches with filters
- Gaming UI: Neon aesthetics with smooth animations
- Stats Tracking: Win/loss records stored in Turso database
- PWA Support: Install as mobile app with offline capabilities
packages/
โโโ hardhat/ # Smart contracts & deployment
โ โโโ contracts/ # Solidity contracts (RPSOnline.sol)
โ โโโ deploy/ # Deployment scripts
โ โโโ scripts/ # Utility scripts
โโโ nextjs/ # Frontend application
โ โโโ app/ # Next.js 13+ app directory
โ โ โโโ game/ # Game interface pages
โ โ โโโ history/ # Match history page
โ โ โโโ play/ # Room creation/joining
โ โ โโโ api/ # Backend API routes
โ โโโ components/ # React components (Header, SelfQRCode)
โ โโโ hooks/ # Custom hooks (useRPSContract)
โ โโโ lib/ # Storage utilities & verification
โ โโโ utils/ # Game utilities (hashing, moves)
โโโ contracts/ # Self Protocol verification contracts
โโโ src/ # Solidity contracts (RPSProofOfHuman.sol)
โโโ script/ # Foundry deployment scripts
โโโ lib/ # Self Protocol dependencies
- Node.js 18+
- Yarn or pnpm
-
Install dependencies
yarn install
-
Start local blockchain
yarn chain
Keep this terminal open - it runs your local Hardhat network.
-
Deploy contracts (in a new terminal)
yarn deploy
This deploys the RPSOnline contract to your local network.
-
Start frontend (in a new terminal)
yarn start
Frontend runs on
http://localhost:3000
RPS OnChain uses Self Protocol to ensure only verified humans can play, preventing bot abuse and maintaining fair gameplay.
- Connect Wallet: Connect your Web3 wallet (MetaMask, MiniPay, etc.)
- Scan QR Code: Use the Self mobile app to scan the verification QR code
- Prove Identity: Self Protocol verifies your identity using zero-knowledge proofs
- Onchain Verification: Your verification status is recorded on Celo blockchain
- Play Games: Access all game features once verified
- Blockchain-First: Verification status checked from Celo smart contract
- Database Fallback: Turso database used if RPC fails (rate limits, timeouts)
- Performance Optimized: Hybrid approach ensures fast loading and reliability
- Privacy Preserving: Zero-knowledge proofs protect your personal information
- Address:
0x3e5e80bc7de408f9d63963501179a50b251cbda3 - Network: Celo Mainnet
- Function:
isUserVerified(address user) returns (bool)
- Connect Wallet: Use any wallet (MetaMask recommended)
- Verify Identity: Scan QR code with Self app to prove you're human
- Choose Mode: Single Player (AI) or Multiplayer (Free)
- Create Room: Generate 6-character room code
- Share Code: Give the room code to your opponent
- Join Room: Enter room code to join
- Choose Move: Select rock, paper, or scissors
- See Results: Winner determined instantly
- Play Again: Request rematch for unlimited games
- Cancel Room: Room creators can cancel unjoined rooms
- Leave Room: Exit after game finishes
- Rematch System: Request/accept rematches instantly
- Rock beats Scissors
- Scissors beats Paper
- Paper beats Rock
- Same moves = Tie
- All games are free
- Stats tracked on IPFS
- Unlimited rematches available
# Blockchain
yarn chain # Start local Hardhat network
yarn deploy # Deploy contracts to local network
yarn deploy --network celo # Deploy to Celo mainnet
yarn deploy --network base # Deploy to Base mainnet
# Self Protocol Verification (Foundry)
cd contracts
forge build # Build verification contracts
forge script script/DeployRPSProofOfHuman.s.sol --rpc-url https://forno.celo.org --broadcast
# Frontend
yarn start # Start Next.js development server
yarn build # Build for production
yarn lint # Run ESLint
# Full stack
yarn dev # Start frontend (same as yarn start)app/page.tsx- Home page with wallet connect & human verificationapp/play/page.tsx- Room creation/joining (free-to-play)app/game/[roomId]/page.tsx- Game interface with commit-revealapp/history/page.tsx- Match history with IPFS linkscomponents/Header.tsx- Navigation with username editingcomponents/SelfQRCode.tsx- Self Protocol verification QR codehooks/useRPSContract.ts- Smart contract interactions & verification status
packages/hardhat/contracts/RPSOnline.sol- RPS game with commit-revealpackages/hardhat/deploy/00_deploy_rps_online.ts- Game contract deploymentcontracts/src/RPSProofOfHuman.sol- Self Protocol verification contractcontracts/script/DeployRPSProofOfHuman.s.sol- Verification contract deployment
app/api/username/route.ts- Username managementapp/api/stats-fast/route.ts- Stats from Turso (direct reads)app/api/store-match/route.ts- Match storage (Turso + IPFS backup)app/api/user-matches/route.ts- Query match history from Tursoapp/api/init-db/route.ts- Initialize Turso database tablesapp/api/migrate-data/route.ts- Migrate Redis data to Tursoapp/api/store-blockchain-proof/route.ts- Blockchain proof storageapp/api/resolve-name/route.ts- ENS/Basename resolutionapp/api/sync-verification/route.ts- Hybrid blockchain + Turso verification syncapp/api/init-verification-table/route.ts- Initialize verification database tableapp/api/debug-verification/route.ts- Debug verification system (development)
utils/gameUtils.ts- Move hashing and game logiclib/tursoStorage.ts- Turso storage layer (users, stats, matches)lib/turso.ts- Turso SQLite database client with verification tableslib/verification.ts- Hybrid blockchain + Turso verification utilitieslib/pinataStorage.ts- IPFS storage utilities (Pinata)lib/upstash.ts- Redis client for active game roomslib/edgeConfigClient.ts- Edge Config clientcontexts/AuthContext.tsx- Unified authentication contexthooks/useGoodDollarClaim.ts- GoodDollar UBI claim integrationstyles/colorThemes.ts- Dynamic color theme systemstyles/fontThemes.ts- Dynamic font theme systemstyles/spacingThemes.ts- Dynamic spacing scale system
Celo Mainnet:
- Game Contract:
0xace7999ca29Fc9d3dfDD8D7F99A1366a5cF62091 - Verification Contract:
0x3e5e80bc7de408f9d63963501179a50b251cbda3 - RPC: https://forno.celo.org
- Gas Token: CELO or cUSD
- Recommended Wallets: MiniPay, MetaMask
Base Mainnet:
- Game Contract:
0x17f238a671CEEa5b6ac9b44E280a42a2Bb080feC - RPC: https://mainnet.base.org
- Gas Token: ETH
- Recommended Wallets: Coinbase Wallet, MetaMask
Local Development:
- Hardhat network (localhost)
Contract addresses are auto-exported to contracts/deployedContracts.ts after deployment.
- โ Self Protocol Onchain Verification: Hybrid blockchain + Turso verification system
- โ Human Verification Required: QR code scanning with Self mobile app
- โ Blockchain-First Architecture: Contract verification with database fallback
- โ Foundry Integration: Self Protocol smart contract deployment
- โ Pivoted to free-to-play model
- โ Removed all betting/paid room functionality
- โ Gaming UI with neon aesthetics and animations
- โ Migrated to Turso as primary database (stats, matches, users, verifications)
- โ Redis for active game rooms only (no stats caching)
- โ IPFS backup storage via Pinata
- โ PWA support with offline capabilities
- โ Dynamic theme system (colors, fonts, spacing)
- โ Unlimited rematch system
- โ On-chain matches page with filters
- โ Per-match publishing with ENS/Basename resolution
- โ Performance optimizations (84% faster load, 60 FPS locked)
- โ GoodDollar UBI daily claims integration
- โ Farcaster & Base miniapp support
- โ MiniPay integration for Celo
- UX Improvements: Fix QR code regeneration after successful verification
- Verification Optimization: Improve database sync reliability
- Tournament brackets with multi-round matches
- Global leaderboards & player statistics
- Achievement system
- Real-time multiplayer lobbies (Random matchmaking)
- Mobile app development
- Optional betting mode (future)
- Multi-chain verification support (Base, Polygon)
- Frontend: Next.js 15, React 18, TypeScript, TailwindCSS
- Wallet: Reown AppKit, Wagmi, Viem
- Blockchain: Hardhat + Foundry, Solidity
- Networks: Celo Mainnet + Base Mainnet (Multi-chain)
- Database: Turso SQLite (primary), Redis (active rooms), IPFS (backup)
- Verification: Self Protocol (@selfxyz/qrcode, @selfxyz/core)
- Architecture: Hybrid blockchain-first with database fallback
- Themes: Dynamic color/font/spacing with CSS variables
- Testing: Vitest + React Testing Library
- Payments: GoodDollar (G$) tipping
- PWA: Service Worker with offline support
- Deployment: Vercel
Create .env files in respective packages:
DEPLOYER_PRIVATE_KEY=your_private_key
PRIVATE_KEY=your_private_key_for_foundry_deployment
RPC_URL=https://forno.celo.org
NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID=your_project_id
# Turso Database (primary storage)
TURSO_DATABASE_URL=libsql://your-database.turso.io
TURSO_AUTH_TOKEN=your_turso_auth_token
# Redis (caching layer)
REDIS_URL=your_redis_url
KV_URL=your_kv_url
KV_REST_API_TOKEN=your_token
KV_REST_API_URL=your_url
# IPFS (backup storage)
PINATA_JWT=your_pinata_jwt_token
NEXT_PUBLIC_IPFS_GATEWAY=https://gateway.pinata.cloud
# Edge Config (legacy - being phased out)
EDGE_CONFIG=https://edge-config.vercel.com/...
EDGE_CONFIG_ID=ecfg_...
VERCEL_API_TOKEN=...
# Optional
NEYNAR_API_KEY=your_neynar_key
JWT_SECRET=your_jwt_secret
-
Install Foundry (if not already installed):
curl -L https://foundry.paradigm.xyz | bash foundryup -
Deploy verification contract:
cd contracts cp .env.example .env # Add your PRIVATE_KEY and RPC_URL forge script script/DeployRPSProofOfHuman.s.sol --rpc-url https://forno.celo.org --broadcast --verify
-
Update frontend configuration:
- Contract address is automatically logged during deployment
- Update
useRPSContract.tswith the new contract address if needed
The verification system uses a hybrid approach with automatic table initialization:
- Tables auto-created on first API call to
/api/sync-verification - Manual initialization (optional):
curl -X POST https://your-domain.com/api/init-verification-table
- QR Code Issues: Ensure Self mobile app is installed and updated
- Contract Issues: Check Celo network connection and contract address
- Database Issues: Use debug endpoint:
GET /api/debug-verification?action=status - Sync Issues: Verification works without database sync (blockchain-first)
After deploying to production:
-
Initialize Turso tables:
curl https://your-domain.com/api/init-db
-
Migrate existing data (if upgrading from Redis-only):
curl -X POST https://your-domain.com/api/migrate-data
- Turso (Primary): Users, stats, matches - persistent, ACID-compliant
- Redis (Temporary): Active game rooms, 7-day match history cache
- IPFS (Backup): Decentralized match storage via Pinata
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
MIT License - see LICENSE file for details.
Ready to play? Run yarn chain, yarn deploy, yarn start and visit http://localhost:3000!