Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

Architecture

Source: denshokan — turnkey implementation of the EGS architecture (token contract, registry, indexer, API, and client).

The Embeddable Game Standard is built around three contract roles: Metagame (the platform), MinigameToken (the shared ERC721), and Minigame (the game logic). These roles communicate through well-defined interfaces discovered via SRC5.

System Diagram

┌─────────────┐         ┌──────────────────┐         ┌─────────────┐
│  Metagame   │──mint──▶│  MinigameToken   │◀──reg───│  Registry   │
│  (Platform) │         │    (ERC721)      │         │             │
│             │◀callback│                  │──read──▶│  Minigame   │
│             │         │  ┌────────────┐  │         │  (Your Game)│
└─────────────┘         │  │ CoreToken  │  │         └─────────────┘
                        │  │ Minter     │  │
                        │  │ Settings   │  │
                        │  │ Objectives │  │
                        │  │ Context    │  │
                        │  │ Renderer   │  │
                        │  │ Lifecycle  │  │
                        │  └────────────┘  │
                        └──────────────────┘

MinigameToken (Center)

The MinigameToken is an ERC721 contract that composes multiple game-components. Each token represents a single game session. The token ID is a packed felt252 encoding immutable game data (game ID, settings, timestamps, flags) directly into the ID itself.

Composed components:
  • CoreTokenComponent - Base lifecycle: mint, update, game over
  • MinterComponent - Tracks who minted each token (platforms, users)
  • SettingsComponent - Stores game setting configurations
  • ObjectivesComponent - Tracks achievement completion
  • ContextComponent - Optional mutable context data
  • RendererComponent - Custom token URI rendering
  • SkillsComponent - Per-token AI agent skills address override
  • ERC721EnumerableComponent - On-chain token iteration

Minigame (Right)

Your game contract implements IMinigameTokenData to expose score and game-over status. When the token contract calls update_game(), it reads your game's state and syncs it to the token.

Metagame (Left)

A platform contract that mints tokens and optionally receives callbacks. If the minter implements IMetagameCallback (discoverable via SRC5), the token automatically dispatches:

  • on_game_action(token_id, score) on every update_game() call
  • on_game_over(token_id, final_score) when a game completes
  • on_objective_complete(token_id) when an objective is met

Registry

The registry maps game contracts to metadata (name, description, developer, genre, image, royalties). Games self-register and receive a creator NFT that controls royalty payments.

Game Lifecycle

1. Setup      Game contract deploys and registers with the Registry
2. Mint       Platform or user calls mint() on MinigameToken
              → Creates packed token ID with game_id, settings, timing
3. Play       Player interacts with the Minigame contract
              → Game updates its internal state (score, progress)
4. Sync       Anyone calls update_game(token_id) on MinigameToken
              → Token reads score/game_over from Minigame via IMinigameTokenData
              → If minter supports IMetagameCallback, dispatches callbacks
5. Complete   Game marks game_over = true
              → Final sync writes permanent result to token

Component Relationships

ComponentDepends OnPurpose
CoreTokenComponentERC721, SRC5Base mint/update/lifecycle
MinterComponentCoreTokenTrack minting addresses with incrementing IDs
SettingsComponentMinigame (IMinigameTokenSettings)Store named setting configurations
ObjectivesComponentMinigame (IMinigameTokenObjectives)Track named objectives and completion
ContextComponentMetagame (IMetagameContext)Store per-token context from platform
RendererComponent-Delegate token URI to external contract
SkillsComponent-Per-token AI agent skills address override

SRC5 Interface Discovery

EGS uses SRC5 (Starknet's equivalent of ERC-165) for runtime interface detection. Before calling an interface method, contracts check supports_interface(interface_id).

This enables safe, optional integration: a token can check if a minter supports callbacks before dispatching, and a platform can check if a game supports settings before querying them.

Interface IDs are defined alongside their traits in the game-components source. See the SRC5 reference → for a full listing.

Deployed Contracts

Mainnet

ContractMainnet Address
MinigameRegistry0x02cbaec07913d3580822e5811e575ab657ee0362c022b8df56214cb6ca95fe06
Denshokan (MinigameToken)0x00263cc540dac11334470a64759e03952ee2f84a290e99ba8cbc391245cd0bf9
DefaultRenderer0x0528a8ddb2dc969e171353780cccb2a2d399bdef4c5cf560e5561dd5dd7bf201
DenshokanViewer0x04b71fe06bc359e5b105857f8d7781b5390066f459c733604abeaa3c6e884875

Sepolia

ContractSepolia Address
MinigameRegistry0x06794040fa260cbc80630b90c5e63f9bc6b1b572d9289175b409e70ae2c234b6
Denshokan (MinigameToken)0x0004e6e5bbf18424dfb825f1dbb65e10473b4603a1ec7b9ab02c143d877114f9
DefaultRenderer0x048236e748d611ac2e0da6a188ec15ecbcd0332091d6ce081312eb1dee905c6a
DenshokanViewer0x010527799357ce3c8e71700b9a13485afcd25304cfebb393919b369845c68f6f
Number Guess0x03a2ea07f0f49c770035eed9a010eb3d1e1bc3cb92e1d47eef2ad75a25c6bdb2

Denshokan = minigame_token_address

The Denshokan contract above is the shared MinigameToken (ERC721) that all EGS games can use. Whenever you see minigame_token_address in the docs or in code (e.g. the game initializer, pre_action, post_action), this is the address to pass.

Using the shared Denshokan contract gives you:

  • Indexing & API — your game is automatically indexed by the Denshokan indexer, giving you REST API, WebSocket, and SDK access out of the box
  • Registry integration — your game appears in the shared game registry alongside all other EGS games
  • Platform compatibility — any EGS platform (tournaments, quests, arcades) can mint tokens for your game immediately
  • Token rendering — default SVG rendering and metadata for all tokens

You can deploy your own MinigameToken contract if you need custom behavior, but most games should use the shared Denshokan contract.

Data Flow

                    ┌─────────────────────────────────────────┐
                    │           Starknet Blockchain            │
                    │                                         │
  mint() ──────────▶│  MinigameToken ◀──── Minigame           │
  update_game() ───▶│       │                  │              │
                    │       ▼                  │              │
                    │  Events (Transfer,       │              │
                    │   ScoreUpdate,           │              │
                    │   GameOver)              │              │
                    └───────┬──────────────────┘              │

                    ┌───────▼───────┐
                    │   Indexer     │  (Apibara)
                    │   ┌───────┐  │
                    │   │ Decode│  │
                    │   │ Events│  │
                    │   └───┬───┘  │
                    └───────┼──────┘

                    ┌───────▼───────┐
                    │  PostgreSQL   │
                    └───────┬───────┘

                ┌───────────┼───────────┐
                │           │           │
         ┌──────▼─────┐ ┌──▼──┐ ┌──────▼──────┐
         │  REST API  │ │ WS  │ │ RPC (direct) │
         └──────┬─────┘ └──┬──┘ └──────┬───────┘
                │           │           │
         ┌──────▼───────────▼───────────▼──────┐
         │         denshokan-sdk               │
         │  (DenshokanClient + React hooks)    │
         └─────────────────────────────────────┘

The SDK provides three data paths:

  1. REST API - Indexed data with filtering, pagination, and aggregation
  2. WebSocket - Real-time event subscriptions (scores, mints, game over)
  3. RPC - Direct contract reads for on-chain truth (ERC721 methods, batch queries)

Smart fallback: if the API is unavailable, the SDK automatically falls back to RPC.