An on-chain Mafia game powered by U2U Blockchain
Built for U2U Vietbuidl Hackathon 2025
Pepasur is a multiplayer Mafia-style social deduction game built entirely on the U2U blockchain. Players take on mythological roles, ASUR (Mafia), DEV (Doctor), MANAV (Villager), and RISHI (Detective) --- and compete through staking, commit-reveal mechanics, and strategic gameplay.
Each game requires players to stake U2U tokens, creating real economic incentives for fair play. Winners receive rewards distributed automatically through smart contracts, while losers get partial refunds. The game features pixel-art styling, real-time multiplayer gameplay, and transparent on-chain mechanics.
- On-chain Mafia Gameplay: Fair play with staking + commit-reveal actions\
- Real Economic Incentives: Stake U2U tokens, win rewards
- Real-time Multiplayer: Socket.io powered live gameplay
- Transparent Rewards: Automatic distribution through smart contracts
- Pixel Art UI: Retro gaming aesthetic with modern Web3 functionality
- Cross-platform: Works on desktop and mobile devices
- Blockchain: U2U Solaris Mainnet & U2U Nebulas Testnet
- Smart Contracts: Solidity + Hardhat
- Backend: Node.js + Express + Socket.io
- Frontend: Next.js + React + TypeScript
- Wallet Integration: RainbowKit + Wagmi
- Game Logic: Commit-reveal cryptography + real-time synchronization
- Game Creation: Players create rooms with customizable stake amounts
- Player Joining: Stake U2U tokens to join games
- Role Assignment: Cryptographic commit-reveal for fair role distribution
- Settlement System: Server-signed settlements for reward distribution
- Withdrawal Mechanism: Players can withdraw rewards anytime
- PepAsur Contract:
0x1fbA70E7A768448EC1Bf34DC53558b47De7b872cโ - RPC URL:
https://rpc-mainnet.u2u.xyz - Block Explorer:
https://u2uscan.xyz
- PepAsur Contract:
0x1fbA70E7A768448EC1Bf34DC53558b47De7b872cโ - RPC URL:
https://rpc-nebulas-testnet.u2u.xyz - Block Explorer:
https://testnet.u2uscan.xyz
- Testnet: Use the built-in faucet to claim 0.5 U2U
- Mainnet: Buy U2U tokens from exchanges
- Create Room: Stake 0.1 U2U to create a 4-player game
- Join Room: Enter room code and stake 0.1 U2U to join
- Night Phase: ASUR eliminate targets, DEV protects, RISHI investigates
- Day Phase: Vote to eliminate suspected ASUR
- Task Phase: Complete mini-games for additional rewards
- Mafia Wins: Mafia takes entire remaining pool, Non-Mafia get nothing
- Non-Mafia Wins: Dead players get 1.75x stake, survivors share remaining pool
- House Cut: 2% goes to platform maintenance
This project simulates a reward distribution system for a Mafia game. Players stake tokens into a shared pool before the round begins. Based on the game outcome --- whether Mafia or Non-Mafia wins --- rewards are distributed accordingly.
- Total Staked Pool โ Sum of all tokens staked by all players.
- House Cut โ A small percentage (e.g., 5--10%) taken by the game as a service fee.
- Remaining Pool โ Total Staked Pool - House Cut.
- Mafia "All In" Rule: If Mafia wins, they take the entire remaining staked pool.
- Non-Mafia Players: Receive nothing.
-
- Survivors (alive till end)
- Dead Non-Mafia (killed during gameplay)
- Dead Non-Mafia Payout: Each gets 1.75x their initial stake.
- Survivors: Share whatever remains of the staked pool after paying the dead non-mafia rewards.
Suppose: - Total Staked Pool = 1000 tokens - House Cut = 10% โ 100 tokens - Remaining Pool = 900 tokens
- Mafia receives 900 tokens
- Non-Mafia receive 0 tokens
- Assume there are 3 dead non-mafia and 2 survivors
- Each dead non-mafia gets 1.75x their stake โ Suppose each staked 100, they get 175 ร 3 = 525 total
- Remaining pool for survivors = 900 - 525 = 375
- Survivors split 375 equally (187.5 tokens each)
- Encourages risk and strategic staking.
- Fairly compensates early victims if non-mafia wins.
- Ensures the game's economy remains sustainable with a house cut.
- Total Pool: 0.4 U2U
- House Cut: 0.02 U2U (5%)
- Remaining Pool: 0.38 U2U
- Mafia Players: Share 0.38 U2U (0.19 U2U each if 2 mafia)
- Non-Mafia Players: Receive 0 U2U
- Total Pool: 0.4 U2U
- House Cut: 0.02 U2U (5%)
- Remaining Pool: 0.38 U2U
- Dead Non-Mafia (2 players): 0.175 U2U each (1.75x stake)
- Survivors (2 players): Share remaining 0.03 U2U (0.015 U2U each)
- Server-Signed Settlements: Only authorized server can submit results
- Player-Controlled Withdrawals: Players must withdraw rewards themselves
- Transparent Transactions: All settlements visible on blockchain
- Commit-Reveal Roles: Cryptographic fairness for role assignment
- Network Latency: Optimizing real-time synchronization between frontend and backend
- State Sync Issues: Resolving game state inconsistencies across multiple players
- UI Responsiveness: Improving user interface performance during gameplay
- Socket.io Integration: Fine-tuning real-time communication for smooth multiplayer experience
- Smart Contract Testing: Comprehensive testing of reward distribution logic
- Cross-platform Compatibility: Ensuring consistent experience across desktop and mobile
- โ Game phase transition logic
- โ Player role assignment system
- โ Room code generation and validation
- โ RainbowKit wallet integration
- โ Runtime error handling
- โ UI component updates
- Network latency can cause temporary state delays
- Mobile UI optimization in progress
- Advanced game analytics implementation pending
- Node.js v18+
- U2U wallet (MetaMask, WalletConnect, etc.)
- U2U tokens for staking
{
chainId: 39,
name: 'U2U Solaris Mainnet',
rpcUrl: 'https://rpc-mainnet.u2u.xyz',
blockExplorer: 'https://u2uscan.xyz',
symbol: 'U2U',
decimals: 18
}{
chainId: 2484,
name: 'U2U Nebulas Testnet',
rpcUrl: 'https://rpc-nebulas-testnet.u2u.xyz',
blockExplorer: 'https://testnet.u2uscan.xyz',
symbol: 'U2U',
decimals: 18
}- Track: Gaming & Entertainment
- Blockchain: U2U Ecosystem
- Innovation: On-chain social deduction game with real economic incentives
- Impact: Demonstrates U2U's capabilities for gaming applications
- Economic Game Design: Staking creates real incentives for strategic play
- Fair Play Mechanisms: Cryptographic commit-reveal ensures role fairness
- Automated Rewards: Smart contracts handle all payouts transparently
- Real-time Multiplayer: Socket.io enables seamless live gameplay
- Cross-platform: Works on any device with U2U wallet support
- Live Demo: www.pepasur.xyz
- Contract Source: GitHub Repository
- U2U Explorer: View on U2UScan