This is a decentralized Rock-Paper-Scissors game built on the Base Sepolia network. The application allows users to create and join games, track their move history, and view past game results, all while ensuring transparency and fairness through blockchain technology.
Tweet link: https://x.com/Jwafo_tweet/status/1917743720113258496
The game's smart contract is deployed on Base Sepolia and can be viewed at: https://sepolia.basescan.org/address/0xc97384de52e31cc4ebe22e06139e36bd7f01211d
To get started with the project, follow these steps:
-
Clone the repository:
git clone https://github.com/yourusername/rockpaperscissors.git cd rockpaperscissors -
Install the dependencies:
npm install
-
Run the development server:
npm run dev
-
Open http://localhost:3000 in your browser to see the application.
- Authentication: Secure login using Civic Auth with embedded wallet functionality
- Network Support: Built specifically for Base Sepolia testnet
- Game Creation: Create custom games with different stakes and game modes
- Game Joining: Search and join existing games by game ID
- Real-Time Gameplay: Make moves and see results in real-time
- Game History: Track all your past games and their outcomes
- Responsive UI: Modern, user-friendly interface with visual feedback
Base Battle Arena offers three different game modes:
- LIGHTNING DUEL - Single round, winner takes all. Perfect for quick games.
- WARRIOR CLASH - First to win 2 rounds. A balanced mode that tests skill and strategy.
- EPIC TOURNAMENT - First to win 5 rounds. For those seeking a more extended battle experience.
Each mode requires a stake in ETH, which is locked in the smart contract until the game concludes.
The application is structured as follows:
- Frontend: Built with Next.js, using React for the UI and Wagmi for Base Sepolia interactions.
- Authentication: Civic Auth provides secure user authentication and wallet management.
- Smart Contracts: The game logic is implemented in Solidity, ensuring secure and transparent gameplay.
- Blockchain: All game states and transactions are recorded on the Base Sepolia network.
-
Frontend Pages:
src/pages/index.tsx: Home page with app overview and wallet connection.src/pages/game.tsx: Main interface for creating and joining games.src/pages/game/[gameId].tsx: Active gameplay interface for a specific game.src/pages/history.tsx: Displays the user's game history and statistics.
-
Game Components:
CreateGame.tsx: UI for creating a new game with customizable settings.JoinGame.tsx: UI for searching and joining existing games.GameSearchCard.tsx: Card component displaying game information.GamePlay.tsx: Interface for making moves during an active game.
-
Network & Contract:
useNetworkInfo.tsx: Hook for accessing Base Sepolia network information.useContractInfo.tsx: Hook for accessing smart contract details.contractInfoBaseSepolia.tsx: Contract address and ABI for Base Sepolia.
- Navigate to the Game tab and select "Create Game"
- Choose your preferred game mode (Lightning Duel, Warrior Clash, or Epic Tournament)
- Set your stake amount in ETH
- Click "FORGE YOUR BATTLE" to create the game
- Share your game ID with an opponent
- Navigate to the Game tab and select "Join Game"
- Enter the game ID of the game you wish to join
- Click "Search" to find the game
- Review the game details and click "JOIN BATTLE"
- Confirm the transaction to join the game
- Once both players have joined, the game will begin
- Each player makes their move (Rock, Paper, or Scissors) during their turn
- After both players have made their moves, the round result is revealed
- This continues until a player has won enough rounds according to the game mode
- Winnings are automatically distributed to the winner's wallet
- Navigate to the History tab to see a list of all your past games
- Click on a game to expand and see detailed information
- View your moves, opponent moves, and the outcome of each round
The game interacts with a Solidity smart contract deployed on Base Sepolia. The contract handles:
- Game creation and joining logic
- Stake management and escrow
- Game state management
- Move validation and result determination
- Reward distribution
- Users authenticate using Civic Auth
- A wallet is automatically created or connected
- The wallet is used for all blockchain transactions
The application is configured to work exclusively with Base Sepolia network:
- Automatic network detection
- Network status notifications
- Support for ETH as the native token
- React hooks for local state management
- Contract events for real-time updates
- Wagmi hooks for blockchain interactions
- Node.js 14+ and npm/yarn
- MetaMask or any other Web3 wallet (optional for testing)
- Base Sepolia testnet ETH (available from faucets)
The project uses environment variables for configuration. Three files are provided:
.env.example- Template file with placeholder values.env.local- For local development.env- For production environment
To set up your environment:
-
Copy
.env.exampleto.env.localfor local development:cp .env.example .env.local
-
Fill in your own values in
.env.local:NEXT_PUBLIC_CONTRACT_ADDRESS=0xYourContractAddressHere NEXT_PUBLIC_BASE_SEPOLIA_RPC_URL=https://sepolia.base.org NEXT_PUBLIC_CIVIC_CLIENT_ID=your-civic-client-id-here NEXT_PUBLIC_NETWORK_ID=84532 NEXT_PUBLIC_APP_NAME=Base Battle Arena
Required environment variables:
NEXT_PUBLIC_CONTRACT_ADDRESS: Address of the game smart contract on Base SepoliaNEXT_PUBLIC_CIVIC_CLIENT_ID: Client ID for Civic Auth authenticationNEXT_PUBLIC_BASE_SEPOLIA_RPC_URL: RPC URL for Base Sepolia network