0GClawForge Documentation
Sovereign Agent OS — comprehensive technical reference
Overview
0GClawForge is a sovereign agent operating system that combines the OpenClaw autonomous agent framework with the 0G decentralized AI ecosystem. It enables the creation, governance, and gameplay of Eternal Clans — on-chain AI collectives that own memory, generate realms, run autonomous behavior, and evolve through community governance.
Core Pillars
- 0G Storage — Content-addressable immutable storage for all agent data (memories, realms, votes)
- 0G Compute — Decentralized AI inference for realm generation, NPC dialogue, and clan chat
- 0G Chain — ERC-7857 intelligent NFTs (iNFTs) that store encrypted agent intelligence on-chain
- OpenClaw — Autonomous agent skills framework for social integrations (Telegram, Discord)
Architecture
The project is a Turbo monorepo with four main packages: the @0gclawforge/sdk TypeScript wrapper library, Solidity smart contracts, the Next.js dashboard application, and the OpenClaw agent fork with custom skills.
Smart Contracts
AgentInft.sol — ERC-7857 Intelligent NFT
The core contract implements ERC-721 with ERC-7857 encrypted metadata extensions. Each token represents a clan with on-chain state tracking for memory, realms, votes, and evolution history.
| Function | Description |
|---|---|
| mintClan(to, uri) | Mints a new clan iNFT with initial metadata URI |
| updateMemoryRoot(tokenId, rootHash) | Updates the 0G Storage root hash for clan memory |
| updateRealmRoot(tokenId, rootHash) | Updates the active realm root hash |
| updateVoteRoot(tokenId, rootHash) | Updates the governance vote chain root |
| getClanState(tokenId) | Returns full on-chain state: memory/realm/vote roots + counters |
| evolve(tokenId, newURI) | Triggers clan evolution, incrementing evolution counter |
Network Deployment
| Network | Chain ID | RPC |
|---|---|---|
| 0G Galileo Testnet | 16602 | https://evmrpc-testnet.0g.ai |
| 0G Mainnet | 16661 | https://evmrpc.0g.ai |
SDK Package
The @0gclawforge/sdk package provides typed wrappers around all 0G SDKs. All application code must use these wrappers instead of calling 0G SDKs directly.
Storage Utilities
uploadJSON(data, config)— Serializes and uploads JSON to 0G Storage, returns root hash + tx hashdownloadFromStorage(rootHash, filePath, config)— Downloads content by root hash to local fileStorageConfig— Type with rpcUrl, indexerUrl, and optional privateKey
Compute Client
ZGComputeClient— Wraps 0G Serving Broker for AI inferenceclient.setupProvider(address)— Initializes the compute providerclient.query(prompt, options)— Sends inference request, returns text + verification status
Contract ABI
agentInftAbi— Exported ABI for the AgentInft contract
0G Storage
0G Storage is a content-addressable immutable storage layer. Every piece of data — memories, realms, vote records — is stored as a JSON blob and identified by its root hash. Root hashes serve as URIs stored on-chain in the iNFT contract.
Data Flow
- Application serializes data to JSON
uploadJSON()writes to 0G Storage via the Indexer- Returns a root hash (content address) and transaction hash
- Root hash is written to the smart contract via
updateMemoryRoot,updateRealmRoot, orupdateVoteRoot - Readers fetch data by calling the contract for the root hash, then downloading from storage
Cross-Network Fallback
When data was uploaded on testnet but is being accessed on mainnet (or vice versa), the system automatically falls back to the testnet storage indexer if the primary network lookup fails. This ensures realm data remains accessible across networks.
Storage Indexers
| Network | Indexer URL |
|---|---|
| Testnet (Galileo) | https://indexer-storage-testnet-turbo.0g.ai |
| Mainnet | https://indexer-storage-turbo.0g.ai |
0G Compute
0G Compute provides decentralized AI inference through a provider network. ClawForge uses the 0GM-1.0-35B-A3B model for all AI-powered features.
Use Cases
- Realm Generation — Transforms user prompts into full game worlds with maps, NPCs, quests, and bosses
- NPC Dialogue — Live in-game NPC conversations powered by realm context and player state
- Clan Chat — Strategic advisor AI with access to realm state and game history
- Proposal Evaluation — AI analysis of governance proposals
- Autonomous Mode — Self-directed clan behavior including auto-proposals and realm evolution
Verification
Each compute response includes a verified flag indicating whether the response was cryptographically verified by the 0G network. Verified responses are labeled verified-0g-compute in the UI.
Realm System & Gameplay
Realms are procedurally generated game worlds created from natural language prompts. Each clan can have an active realm stored on 0G Storage with full version history.
Realm Structure
- Map — 16×16 tile grid with terrain types (grass, stone, water, wall, lava, sand, forest, ice)
- NPCs — Named characters with descriptions, dialogue, positions, and optional quest assignments
- Quests — Named objectives with descriptions, types (fetch, kill, explore, puzzle), and reward items
- Artifacts — Collectible items placed on the map with stat effects
- Boss — End-game enemy with HP, attack, defense, and loot tables
- Spawn Point — Player starting position
Generation Pipeline
When a clan owner submits a realm prompt, the system first attempts AI generation via 0G Compute. If compute is unavailable, it falls back to a deterministic generator that uses time-based randomness to create unique realms from prompt keywords.
Gameplay Mechanics
- Movement — WASD or arrow keys on the tile map
- Combat — Turn-based attacks against the boss, using base attack + weapon bonuses
- Quests — Talk to NPCs, complete objectives, earn inventory items
- Artifacts — Walk over to collect, granting HP/attack/defense bonuses
- Progress Saving — Player state (HP, XP, gold, level, inventory) saved to 0G Storage
- Realm History — Previous realm versions accessible via
previousRealmRootURIchain
Governance & Voting
Clans are governed through an on-chain proposal and voting system. Any member can submit proposals, and the community votes to accept or reject them.
Proposal Flow
- A member submits a proposal (via dashboard or Telegram bot)
- The proposal is evaluated by 0G Compute AI for feasibility
- Community members cast Yes/No votes
- Vote results are stored as a linked list on 0G Storage
- Each vote record contains a
previousVoteRootpointer to the prior vote - The latest vote root hash is written to the smart contract
Vote History
The Vote History panel (in the Governance tab) traverses the vote chain by followingpreviousVoteRoot links from 0G Storage, displaying all past proposals with their vote counts, pass/reject status, timestamps, and storage hashes.
Vote Record Structure
| Field | Description |
|---|---|
| proposal | The proposal text |
| yesVotes | Number of yes votes |
| noVotes | Number of no votes |
| previousVoteRoot | Root hash of the previous vote record (linked list) |
| createdAt | Timestamp of vote creation |
Autonomous Mode
Autonomous mode allows clans to operate independently — proposing realm changes, evolving their identity, and managing governance without constant human input.
Capabilities
- Auto-Proposals — AI generates governance proposals based on clan state and history
- Realm Evolution — Automatic realm generation and updates
- Memory Management — Clan memory updates based on events and interactions
- Social Posting — Automated updates via Telegram/Discord bots
Autonomous behavior is powered by 0G Compute inference and coordinated through the OpenClaw skills framework. All autonomous actions are recorded on 0G Storage for full auditability.
API Routes
All API routes are Next.js App Router server functions under /api/.
| Route | Methods | Description |
|---|---|---|
| /api/clans | GET, POST | List clans, create proposals, store votes, generate realms, manage memory |
| /api/realm/[tokenId] | GET, POST | Fetch realm with version history; save player progress |
| /api/realm/[tokenId]/chat | POST | Clan advisor chat powered by 0G Compute |
| /api/realm/[tokenId]/npc | POST | Live NPC dialogue with realm context |
| /api/votes | GET | Fetch vote history chain from 0G Storage |
| /api/agents | GET, POST | Agent registry and management |
| /api/autonomy | POST | Trigger autonomous clan behavior |
| /api/compute | POST | Direct 0G Compute inference endpoint |
| /api/forge | POST | Clan forging (minting) operations |
| /api/marketplace | GET | Browse available clans and agents |
| /api/memory | GET, POST | Clan memory retrieval and updates |
Dashboard Pages
| Page | Path | Description |
|---|---|---|
| Home / App | / | Main clan management dashboard with tabs for Overview, Memory, Governance, Realm, Chat, Autonomous |
| Play | /play | Browse and enter playable clan realms |
| Play Realm | /play/[tokenId] | Full game engine — tile map, combat, quests, NPCs, inventory, boss fights |
| Forge | /forge | Create new clans by minting ERC-7857 iNFTs |
| Marketplace | /marketplace | Browse and discover clans and agents |
| Memory | /memory | View and manage clan memory blobs |
| Swarm | /swarm | Multi-agent swarm coordination view |
| Docs | /docs | This documentation page |
Security Model
Key Principles
- Private keys are server-side only — Never exposed in client-side bundles or browser code
- ERC-7857 encryption — Agent intelligence blobs are encrypted before storage on 0G
- Wallet-gated actions — Mutations require connected wallet signatures
- Content addressing — 0G Storage root hashes are tamper-proof; data integrity is guaranteed by the network
- Compute verification — 0G Compute responses include cryptographic verification flags
Environment Variables
| Variable | Description | Required |
|---|---|---|
| PRIVATE_KEY | Server-side signing key for 0G Storage/Compute | Yes |
| OG_COMPUTE_PROVIDER_ADDR | 0G Compute provider address | For AI features |
| NEXT_PUBLIC_OG_CHAIN_ID | Default chain ID (16602 or 16661) | No (defaults to 16602) |
| NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID | WalletConnect project ID | For wallet connections |
Network Reference
0G Galileo Testnet
| Service | Endpoint |
|---|---|
| RPC | https://evmrpc-testnet.0g.ai |
| Storage Indexer | https://indexer-storage-testnet-turbo.0g.ai |
| Faucet | https://faucet.0g.ai |
| Explorer | https://chainscan-galileo.0g.ai |
| Chain ID | 16602 |
0G Mainnet
| Service | Endpoint |
|---|---|
| RPC | https://evmrpc.0g.ai |
| Storage Indexer | https://indexer-storage-turbo.0g.ai |
| Chain ID | 16661 |
Development Guide
Prerequisites
- Node.js 18+
- pnpm 8+
- A 0G testnet wallet with test tokens (get from faucet)
Getting Started
Clone the repository, install dependencies with pnpm install, copy.env.example to .env and fill in your private key and compute provider address.
Common Commands
| Command | Description |
|---|---|
| pnpm install | Install all dependencies |
| pnpm dev | Start development server |
| npx next build | Production build (use this, not turbo build) |
| pnpm deploy:testnet | Deploy contracts to 0G testnet |
Project Structure
| Path | Description |
|---|---|
| apps/dashboard/ | Next.js 14 dashboard application |
| apps/openclaw-fork/ | OpenClaw agent fork with custom skills |
| packages/sdk/ | TypeScript SDK wrapping all 0G services |
| packages/contracts/ | Solidity smart contracts |
| agents/ | Telegram/Discord bot and social integrations |
Social Integrations
Telegram Bot
The Telegram bot provides a conversational interface to clan features directly in group chats or DMs.
Discord Bot
The Discord integration mirrors Telegram functionality with slash commands, enabling clan management from Discord servers. Uses the same underlying handler system for consistent behavior across platforms.