Multiplayer Mafia game with ETH prizes, built as a Farcaster Frame on Base L2.
- 9 Players: Exactly 9 players per game
- Entry Fee: 0.001 ETH (testnet)
- Roles: 2 Mafia, 1 Doctor, 1 God, 5 Villagers
- Duration: 3 rounds max, ~15 minutes
- Platform: Farcaster Frames (no app needed!)
- Frontend: Next.js + Farcaster Frames
- Backend: Next.js API routes + Redis state
- Blockchain: Base Sepolia testnet
- Wallet: Privy embedded wallets
- Images: @vercel/og dynamic generation
git clone <your-repo>
cd blockmafia-frame
npm installcp .env.example .env.local
# Fill in your API keys:
# - NEYNAR_API_KEY (Farcaster)
# - UPSTASH_REDIS_URL & TOKEN (Redis)
# - ALCHEMY_BASE_KEY (Base network)
# - PRIVY_APP_ID & SECRET (Wallets)
# - PRIVATE_KEY (Deployer wallet)# Compile contract
npm run hardhat:compile
# Deploy to Base Sepolia
npm run hardhat:deploy
# Update .env.local with contract addressnpm run dev- Use Frame Ground to test locally
- Share frame URL in Warpcast to test live
src/
├── app/api/
│ ├── frame/ # Frame endpoints
│ ├── og/ # Image generation
│ └── cron/ # Timer jobs
├── lib/
│ ├── game-engine.ts # Game logic
│ ├── redis.ts # State management
│ ├── frame-utils.ts # Frame helpers
│ └── types.ts # TypeScript types
├── contracts/
│ └── SimpleMafiaEscrow.sol
└── scripts/
└── deploy.ts
- Create/Join: Host creates game, players join via frame
- Payment: Players pay 0.001 ETH entry fee (embedded wallet)
- Start: Game starts when 9 players joined
- Roles: Secret roles assigned via private DMs
- Day Phase: 5min discussion, vote to eliminate
- Night Phase: Mafia kills, Doctor saves
- Win: Mafia wins if they equal villagers, else villagers win
GET/POST /api/frame- Main landingPOST /api/frame/create- Create gamePOST /api/frame/join- Join gamePOST /api/frame/lobby- Lobby statePOST /api/frame/start- Start gamePOST /api/frame/game- Game state
GET /api/og?type=landing- Landing imageGET /api/og?type=lobby&gameId=X&playerCount=5- LobbyGET /api/og?type=game&phase=day&round=1&userRole=mafia- Game
# Development
npm run dev # Start dev server
npm run build # Build for production
npm run typecheck # TypeScript check
# Smart Contracts
npm run hardhat:compile # Compile contracts
npm run hardhat:test # Run tests
npm run hardhat:deploy # Deploy to testnetThis is built for Base Sepolia testnet with 0.001 ETH entry fees. DO NOT use on mainnet without proper audits and legal review.
Online gaming with real money requires legal compliance in many jurisdictions. Consult legal counsel before accepting real ETH.
Built with ❤️ by Deb
Ready to play? Share the frame in Warpcast and let the games begin! 🎭