A production-ready xTicTacToe game built as a Farcaster MiniApp with blockchain integration on Base.
- AI Mode (Free): Practice against AI with adjustable difficulty (Easy, Medium, Hard)
- PvP Mode ($1 USDC): Compete against other players for real money
- 🎮 Matchmaking Lobby: Find opponents in real-time
- 🏆 Ranked Leaderboard: Track your wins and climb the rankings
- ✨ Animated UI: Winning cells glow with smooth animations
- 🔊 Sound Effects: Audio feedback for moves, wins, and matches
- 📳 Haptic Feedback: Vibration support for mobile devices
- 🎚️ AI Difficulty Slider: Easy, Medium, or Hard opponent
- ⚡ Gas-Sponsored Entry: Optional free gas for PvP matches
- Next.js 14 (App Router)
- TypeScript (Strict mode)
- Tailwind CSS (Carton theme)
- REOWN AppKit (Wallet connection)
- Wagmi + Viem (Ethereum interaction)
- Base Chain (USDC payments)
- Solidity (Smart contract escrow)
tictactoe-farcaster/
├── contracts/
│ └── TicTacToeEscrow.sol # Solidity escrow contract
├── public/
│ └── farcaster.json # Farcaster manifest
├── src/
│ ├── app/
│ │ ├── layout.tsx # Root layout
│ │ ├── page.tsx # Main app page
│ │ └── globals.css # Global styles
│ ├── components/
│ │ ├── GameBoard.tsx # xTicTacToe board
│ │ ├── ModeSelector.tsx # Game mode selection
│ │ ├── MatchmakingLobby.tsx # Player matchmaking
│ │ ├── WaitingRoom.tsx # Pre-game setup
│ │ └── Leaderboard.tsx # Rankings display
│ ├── config/
│ │ ├── appkit.tsx # REOWN AppKit setup
│ │ └── contracts.ts # Contract addresses & ABIs
│ ├── hooks/
│ │ └── useContract.ts # Contract interaction hooks
│ └── utils/
│ ├── game.ts # Game logic & AI
│ └── sound.ts # Audio & haptics
├── package.json
├── next.config.js
├── tailwind.config.js
├── tsconfig.json
└── .env.example
Features:
- USDC-based escrow on Base
- Gas-sponsored entry option
- Stats tracking (wins/losses)
- Leaderboard support
Key Functions:
createGame(opponent)- Create new game with USDCcreateGameSponsored(player1, opponent)- Gas-sponsored creationjoinGame(gameId)- Join existing gamejoinGameSponsored(gameId, player2)- Gas-sponsored joinpayout(gameId, winner)- Distribute winningsgetPlayerStats(address)- Get win/loss record
Economics:
- Entry fee: 1 USDC per player
- Total pot: 2 USDC
- Winner receives: 1.70 USDC
- Creator fee: 0.30 USDC
cd tictactoe-farcaster
npm installcp .env.example .env.localEdit .env.local:
NEXT_PUBLIC_REOWN_PROJECT_ID=your_reown_project_id
Get your REOWN Project ID from: https://cloud.reown.com
# Install Hardhat/Foundry
# Deploy to Base
# Update CONTRACT_ADDRESS in src/config/contracts.tsnpm run devnpm run build
npm startvercel deployEdit public/farcaster.json with your deployed URLs:
homeUrl: Your app URLiconUrl: App icon (512x512 PNG)imageUrl: Preview image (1200x630 PNG)splashImageUrl: Splash screen
// hardhat.config.js
module.exports = {
solidity: "0.8.20",
networks: {
base: {
url: "https://mainnet.base.org",
accounts: [process.env.PRIVATE_KEY]
}
}
};npx hardhat run scripts/deploy.js --network baseforge create TicTacToeEscrow \
--rpc-url https://mainnet.base.org \
--private-key $PRIVATE_KEY \
--constructor-args $PAYMASTER_ADDRESSUpdate src/config/contracts.ts:
export const CONTRACT_ADDRESS = '0x...'; // Your deployed contract
export const USDC_ADDRESS = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913'; // Base USDCEdit tailwind.config.js to customize the carton theme colors.
- Select "AI Mode"
- Adjust difficulty slider
- Play immediately (free)
- Select "PvP Mode"
- Enter matchmaking lobby
- Quick match or challenge specific player
- Approve USDC (or use gas-sponsored)
- Create/join game
- Play match
- Winner receives payout automatically
Use WebSocket or Server-Sent Events for real-time matchmaking:
// Example WebSocket integration
const ws = new WebSocket('wss://your-api.com/matchmaking');
ws.send(JSON.stringify({ action: 'findMatch', userId }));Fetch from subgraph or backend API:
const response = await fetch('/api/leaderboard?limit=10');
const data = await response.json();- Chrome/Edge 90+
- Safari 14+
- Firefox 88+
- Mobile browsers with Web3 wallet support
Run the test suite with:
npm testFor coverage report:
npm run test:coverageMIT
- Never commit
.env.local - Audit smart contracts before mainnet deployment
- Use hardware wallet for contract deployment
- Enable two-factor authentication on Vercel/hosting
For issues or questions, please open a GitHub issue.