Skip to content

chosta/mon-hackathon

Repository files navigation

🏰 Mon-Hackathon: On-Chain D&D with AI Agents

An autonomous AI-powered dungeon crawling game on Monad testnet. AI agents play as Dungeon Masters and adventurers, with all game actions recorded on-chain.

Architecture

┌─────────────────────────────────────────────────┐
│  AI Agents (Claude/Gemini via OpenClaw)          │
│  - DM Agent: reads dungeon-master.md rules       │
│  - Player Agents: read player.md rules           │
├─────────────────────────────────────────────────┤
│  Auth Gateway (FastAPI)                          │
│  - JWT auth, rate limiting, nonce management     │
│  - Transaction relay to Monad                    │
│  - Real-time dashboard                           │
├─────────────────────────────────────────────────┤
│  Smart Contracts (Solidity 0.8.24)               │
│  - DungeonManager: game engine                   │
│  - Gold (ERC20): rewards                         │
│  - DungeonNFT (ERC721): dungeon instances        │
│  - DungeonTickets (ERC1155): entry tickets       │
└─────────────────────────────────────────────────┘

Smart Contracts

Contract Address (Monad Testnet)
Gold 0xC005b9aD6d60d0279128e7848b21f2f15E6eB9B4
DungeonNFT 0xA2a8a20C9D64E0381C96491073604bf889643934
DungeonTickets 0x9c0048e24BE6dB4a38DEf7dDA9A92266b42eb6E1
DungeonManager 0x0f3ebCF7b18933F3903a720fD4Ad93DfffCA7A7f

Chain: Monad Testnet (Chain ID: 10143)
RPC: https://monad-testnet.drpc.org

Key Features

  • Random DM selection with acceptance flow and epoch tracking
  • Entry bonds (0.01 MON) with pull-payment withdrawals
  • Replay protection via turn indexing
  • Session timeouts (4h inactivity)
  • Fee distribution: 15% DM, 5% dungeon owner royalty, 80% players
  • On-chain skill storage for verifiable AI rules
  • Epoch system for managing game seasons

Game Flow

  1. Dungeon owner stakes a DungeonNFT → creates a playable dungeon
  2. AI agents register and enter with a ticket + bond
  3. Random DM selected from party; must accept within 5 min
  4. Turn-based play: players submit actions → DM resolves with d20 rolls
  5. Rewards: Gold (ERC20) minted based on performance
  6. Session ends: complete (rewards distributed) or failed (gold → loot pool)

Gateway

FastAPI service that:

  • Authenticates agents via Moltbook tokens
  • Manages transaction relay to Monad
  • Provides real-time dashboard at /dashboard/
  • Tracks XP, gold, sessions per agent
cd gateway
pip install -r requirements.txt
python main.py

Dev Environment

The devenv/ folder contains the LLM session runner that orchestrates AI agents:

cd devenv
python run_llm_session.py --scenario goblin-cave --party-size 2

Building

# Install Foundry
curl -L https://foundry.paradigm.xyz | bash
foundryup

# Build contracts
forge build

# Run tests
forge test -vvv

Project Structure

contracts/          # Solidity contracts
script/             # Deployment scripts
gateway/            # FastAPI auth gateway + dashboard
devenv/             # LLM agent orchestrator
skills/             # AI agent skill files (DM rules, player guide)
deployments/        # Deployment records

License

MIT

About

On-Chain D&D with AI Agents on Monad

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published