A decentralized Rock, Paper, Scissors game built on the Kaia blockchain
- Classic RPS: Play Rock, Paper, Scissors against an AI bot
- Commit-Reveal Scheme: Secure move submission using cryptographic hashing
- Winning Incentives: Set your own participation fee (0.01 - 100 KAIA)
- Instant Payouts: Win 2x your participation fee when you beat the bot
- Forfeit Protection: Ability to forfeit games if needed
- Modern UI: Clean, responsive design with Tailwind CSS
- Wallet Integration: Seamless Web3Onboard wallet connection
- Real-time Feedback: Live game state updates and transaction status
- Visual Feedback:
- Confetti animation for wins (6 seconds)
- Outcome feedback with move images
- Prize money display for victories
- Smooth animations and transitions
- Game History: Track your games and view global statistics
- Mobile Responsive: Optimized for all screen sizes
- Smart Contract: Solidity-based game logic with security features
- Gas Optimization: Dynamic gas estimation with fallback mechanisms
- Error Handling: Comprehensive error messages and user feedback
- Performance: Optimized with React hooks (useMemo, useCallback)
- Component Architecture: Modular, reusable components
- Liquidity Management: Deposit/withdraw KAIA to control betting capacity
- Owner Controls: Secure withdrawal functions for contract owner
- Real-time Monitoring: Track contract balance, reserved liquidity, and available funds
- Automated Scripts: Easy-to-use CLI tools for contract administration
- Node.js (v16 or higher)
- npm or yarn
- MetaMask or compatible Web3 wallet
- KAIA testnet tokens for gameplay
-
Install dependencies
npm install
-
Environment Setup
# Copy environment variables (if needed) cp .env.example .env -
Start the development server
npm run dev
-
Open your browser Navigate to
http://localhost:3000
- Click "Connect Wallet" in the navigation bar
- Approve the connection in your wallet
- Enter your participation fee (minimum 0.01 KAIA)
- Use quick buttons (0.01, 0.1, 1, 10) for convenience
- Ensure you have sufficient KAIA balance
- Ensure your participation fee is lower than the contract's balance
- Select Rock, Paper, or Scissors
- Generate a random salt for security
- Click "Commit Move" to submit your encrypted move
- After the bot commits, reveal your move
- Click "Reveal Move" to complete the game
- View the outcome and collect your winnings!
- View your game history in the "My Games" tab
- Check global statistics in the "Global Games" tab
- Monitor ongoing games with visual indicators
- KaiaGame.sol: Main game contract
- Functions:
commitMove(bytes32 hash): Submit encrypted moverevealMove(uint8 move, string salt): Reveal move and resolve gameforfeitCurrentGame(): Forfeit active gamegetCurrentGame(address player): Get player's active gamegetLatestGames(uint256 count): Get recent global gamesgetLatestGamesOf(address player, uint256 count): Get player's games
- Color Scheme: Kaia brand colors with custom accents
- Typography: Modern, readable fonts
- Animations: Smooth transitions and micro-interactions
- Custom Scrollbar: Thin, branded scrollbar design
- Desktop: Full-featured layout with side-by-side panels
- Tablet: Optimized spacing and touch targets
- Mobile: Stacked layout with mobile-friendly controls
- Hover Effects: Scale and glow effects on interactive elements
- Loading States: ClipLoader animations for transactions
- Feedback Banners: Success, error, and warning messages
- Game States: Visual indicators for ongoing, completed, and forfeited games
- Commit Phase: Player submits
keccak256(abi.encodePacked(move, salt)) - Reveal Phase: Player reveals actual move and salt
- Verification: Contract verifies hash matches reveal data
- Reentrancy Protection: Prevents attack vectors
- Input Validation: Comprehensive parameter checking
- State Management: Proper game state transitions
- Error Handling: Graceful failure modes
npx hardhat compile # Compile contracts
npx hardhat deploy # Deploy contracts# Deposit KAIA into contract (increase liquidity)
npm run deposit # Default: 10 KAIA
# Withdraw KAIA from contract (owner only)
npm run withdraw # Withdraw all unreserved liquidity
npm run withdraw:all # Same as above
npx hardhat run scripts/withdraw.cjs --network kaia 25.5 # Custom amount- Rock beats Scissors
- Paper beats Rock
- Scissors beats Paper
- Draw: Same moves result in refund
- Win: 2x participation fee
- Lose: 0x (fee goes to contract)
- Draw: 1x (full refund)
- Forfeit: 0x (fee goes to contract)
- Setup: Player sets bet and connects wallet
- Commit: Player submits encrypted move
- Bot Commit: AI bot commits its move
- Reveal: Player reveals move and game resolves
- Payout: Winnings distributed automatically
- Win: Green background, confetti (6s), prize display
- Lose: Red background, move images shown
- Draw: Yellow background, move images shown
- Page Load: Fade-in animation for all components
- Button Interactions: Hover effects and loading states
- Game Transitions: Smooth state changes
- Mobile Optimizations: Touch-friendly interactions
- Touch Targets: Minimum 44px for all interactive elements
- Gesture Support: Swipe-friendly navigation
- Viewport Optimization: Proper scaling and spacing
- Performance: Optimized for mobile devices
- Stacked Layout: Vertical arrangement on small screens
- Simplified Navigation: Streamlined mobile menu
- Touch Feedback: Visual feedback for touch interactions
NEXT_PUBLIC_ENV = "TESTNET"
PRIVATE_KEY = your_private_key (only required if you want to deploy the RPS Contract)
KAIA_RPC_URL = rpc_url
CHAIN_ID = chain_id
NEXT_PUBLIC_KAIA_GAME_ADDRESS = deployed_rps_addressThis project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- Create an issue in the repository
- Check the documentation
- Review the smart contract code
Built with โค๏ธ for the Kaia blockchain community