On-chain escrow + off-chain skill game (Agar-style) with USDC buy-ins and EIP-712 voucher payouts.
ValueAgar is a minimal prototype demonstrating trustless custody and payouts (on-chain) with responsive gameplay (off-chain). Players pay $1 USDC to join a 10-minute round of an Agar.io-style game. In-game value (credits) transfers off-chain via gameplay. Players can "Retire & Bank" to lock their value, and at round end, the server signs an EIP-712 payout voucher that players can use to claim USDC from the on-chain escrow contract.
- Smart Contract: Escrow + payouts — trustless
- Server: Gameplay referee + voucher signer — trusted for fairness (transparent and deterministic)
- Client: Untrusted (display + inputs only)
- Contracts: Solidity smart contracts deployed on testnet (Sepolia or L2)
- Server: Node.js/TypeScript game server with WebSocket and REST API
- Web: React frontend with Web3 integration
- Node.js 18+
- npm or yarn
- Hardhat for contract deployment
- Testnet wallet with test USDC
Copy .env.example to .env and fill in:
RPC_URL: Ethereum RPC endpointCHAIN_ID: Chain ID (e.g., 11155111 for Sepolia)USDC_ADDRESS: USDC ERC-20 token address on testnetCONTRACT_ADDRESS: Deployed DemoValueAgar contract addressSERVER_PRIVKEY: Private key for voucher signing (EOA)ENTRY_FEE: Entry fee in token units (1000000 = 1.0 USDC with 6 decimals)SESSION_LENGTH_MS: Session duration in milliseconds (600000 = 10 minutes)JOIN_CLOSE_MS: Join window close time before session end (120000 = 2 minutes)TICK_RATE: Game tick rate per second (30)SNAPSHOT_RATE: Snapshot broadcast rate per second (12)
cd contracts
npm install
npx hardhat compile
npx hardhat test
npx hardhat run scripts/deploy.ts --network sepoliacd server
npm install
npm run build
npm startcd web
npm install
npm run dev- Lobby: Connect wallet, approve USDC, join session
- Arena: Play game, move around, eat other players, accumulate credits
- Retire & Bank: Lock your credits (optional, can wait for round end)
- Settle: Fetch voucher, claim USDC from contract
- User can connect wallet on testnet
- User can approve 1 USDC and call
join(sessionId) - User can enter Arena and move around
- User can eat/transfer value and see HUD update
- User can click "Retire & Bank" to freeze value
- User can fetch voucher and successfully claim USDC from contract
- Demo/testnet only — no real money
- Server is trusted for gameplay fairness
- Single server instance (no distributed consensus)
MIT