GamePay: Decentralized Pay-Per-Second Gaming Infrastructure
GamePay: Decentralized Pay-Per-Second Gaming Infrastructure GamePay is a revolutionary blockchain-based payment system that enables pay-per-second gaming sessions with real-time billing. Built for ETHIndia, it solves the problem of traditional gaming payment models by allowing players to pay only for the time they actually play, with automatic refunds for unused session time. Key Features: Pay-Per-Second Billing: Players are charged only for actual gameplay time, not fixed session durations EIP-712 Signed Offers: Secure, off-chain signed payment offers that prevent replay attacks and ensure authenticity Real-Time Billing: WebSocket-powered real-time spending updates so players always know their current session cost Automatic Refunds: Unused session budget is automatically refunded when sessions close Multi-Game Support: Dynamic game registry supporting different games with varying rates per second ERC20 Token Integration: Built-in support for USDC and other ERC20 tokens for payments Gas-Optimized: Smart contracts designed for minimal gas consumption with efficient session management
How It Works: Players select a game and set a spending budget The system generates a cryptographically signed payment offer using EIP-712 Players approve token spending and open a metered session Real-time WebSocket updates show current spending as they play When done, players close the session and receive automatic refunds for unused time This system eliminates the need for upfront payments, subscription models, or complex billing systems, making gaming more accessible and fair for players while providing developers with a reliable, automated payment infrastructure. How it's made: Architecture & Technologies: Smart Contracts (Solidity): PaymentSession.sol: Core escrow contract implementing pay-per-second metering with EIP-712 signature verification GameRegistry.sol: Dynamic game management system with owner-controlled game registration and signer assignment MockUSDC.sol: ERC20 token for testing with owner-controlled minting for faucet functionality Frontend (Next.js + React): Wagmi + Viem: Modern React hooks for Ethereum interaction with automatic RPC management Real-time UI: Live spending updates via WebSocket integration Multi-chain Support: Automatic chain detection and contract address mapping Gas Optimization: Explicit gas limits to bypass MetaMask estimation issues Backend (Node.js + Fastify): EIP-712 Signing: Server-side cryptographic signing of payment offers using private key management WebSocket Server: Real-time session spending updates with automatic polling Faucet System: Automated token distribution for testing and user onboarding CORS & Security: Proper cross-origin handling and input validation Development Infrastructure: Monorepo Structure: pnpm workspaces for efficient dependency management Hardhat: Comprehensive deployment and verification system for Polygon Amoy TypeScript: Full type safety across contracts, frontend, and backend Environment Security: Proper .env handling with example files and gitignore protection Notable Technical Achievements: EIP-712 Implementation: Custom domain separator and type hashing for secure off-chain signatures Gas-Efficient Session Management: Optimized storage patterns and reentrancy protection Real-time Synchronization: WebSocket polling with automatic session state updates Multi-Chain Deployment: Automated deployment scripts for testnet and mainnet compatibility Security Hardening: Comprehensive input validation, nonce management, and signature verification Partner Technology Benefits: Polygon Amoy: Fast, low-cost transactions perfect for gaming micro-payments Alchemy RPC: Reliable blockchain connectivity with automatic retry and caching Wagmi Framework: Simplified React integration with automatic chain switching and account management The system demonstrates advanced smart contract patterns, real-time web integration, and production-ready security practices, making it a comprehensive solution for the future of gaming payments.

