Canvas-based Monopoly game featuring AI-powered players using Claude Haiku 4.5 and blockchain micropayments via the X402 protocol.
- Complete Monopoly mechanics - 40 squares, properties, trading, houses/hotels, bankruptcy
- AI-powered purchase decisions - Claude Haiku 4.5 with prompt caching for strategic gameplay
- X402 payment protocol - AUSD token micropayments on Base Sepolia
- Real-time visualization - Canvas-based board with balance history charts
- Configurable strategies - Simple, aggressive, conservative, or AI-driven players
-
Clone and install dependencies:
git clone <repo-url> cd monopoly pnpm install
-
Configure environment variables (see Environment section)
-
Start the game server:
PLAYERS_CONFIG=examples/players-ai.json npx tsx src/main.ts
-
Build the client:
npx esbuild src/index.ts --bundle --outfile=index.js
-
Open
index.htmlin your browser
src/
├── index.ts # Browser client - Canvas-based game rendering
├── main.ts # Game server entry point
├── game/
│ ├── gameServer.ts # Express server with game state management
│ ├── card.ts # Board positions and property definitions
│ └── player.ts # Player state and strategy handling
└── payment/
└── x402.ts # X402 payment protocol implementation
- Client: Canvas-based browser game with real-time board visualization
- Server: Express.js handling player joins, moves, and property transactions
- Payments: X402 protocol with EIP-712 signatures for micropayments
Create a .env file with:
# Server wallet (receives payments)
SERVER_ADDRESS=0x...
SERVER_PK=0x...
# Anthropic API (for AI players)
ANTHROPIC_API_KEY=sk-ant-...
# Optional
PORT=3000Player configs define starting conditions and strategies. See examples/ folder:
| File | Description |
|---|---|
players.json |
Basic 2-player setup |
players-ai.json |
AI players with custom strategy prompts |
players-bankruptcy.json |
Bankruptcy testing scenario |
players-trading.json |
Trading system testing |
Example AI player config:
{
"name": "Aggressive Alice",
"color": "blue",
"strategy": "ai",
"strategyPrompt": "Buy every property you can afford. Prioritize completing monopolies.",
"initialBalance": 5000
}- TypeScript - Type-safe development
- Express - Game server
- Canvas API - Board visualization
- Viem - Ethereum interactions
- Anthropic SDK - AI player decisions
- Token: AUSD on Base Sepolia
- Contract:
0xa9012a055bd4e0eDfF8Ce09f960291C09D5322dC - Join cost: 100 AUSD
- Move cost: 200 AUSD per turn
MIT
