MetagameComponent
The MetagameComponent is the foundation for platform contracts that integrate with EGS games. It provides context management, game state callbacks, and the base interface that platforms embed.
Core Interface: IMetagame
pub const IMETAGAME_ID: felt252 =
0x7997c74299c045696726f0f7f0165f85817acbb0964e23ff77e11e34eff6f2;
#[starknet::interface]
pub trait IMetagame<TContractState> {
fn context_address(self: @TContractState) -> ContractAddress;
fn default_token_address(self: @TContractState) -> ContractAddress;
}context_address— returns the address of the contract providing context data for tokensdefault_token_address— returns the default MinigameToken contract address this platform uses
Context Extension
Platforms can attach context data to tokens. The token contract checks for this interface via SRC5 before reading context.
IMetagameContext
pub const IMETAGAME_CONTEXT_ID: felt252 =
0x1633419b5abcc4c0bbed8bd37a363fbe6de5bd25908761ab6dcda6a9b598ca9;
#[starknet::interface]
pub trait IMetagameContext<TState> {
fn has_context(self: @TState, token_id: felt252) -> bool;
}IMetagameContextDetails
#[starknet::interface]
pub trait IMetagameContextDetails<TState> {
fn context_details(self: @TState, token_id: felt252) -> GameContextDetails;
}IMetagameContextSVG
#[starknet::interface]
pub trait IMetagameContextSVG<TState> {
fn context_svg(self: @TState, token_id: felt252) -> ByteArray;
}Callback Extension
Metagame contracts can receive automatic callbacks from token contracts when game state changes. This enables tournament score aggregation without manual syncing.
IMetagameCallback
pub const IMETAGAME_CALLBACK_ID: felt252 =
0x3b4312c1422de8c35936cc79948381ab8ef9fd083d8c8e20317164690aa1600;
#[starknet::interface]
pub trait IMetagameCallback<TState> {
/// Called on every update_game() call
fn on_game_action(ref self: TState, token_id: u256, score: u64);
/// Called when game_over transitions to true
fn on_game_over(ref self: TState, token_id: u256, final_score: u64);
/// Called when the objective is completed
fn on_objective_complete(ref self: TState, token_id: u256);
}The token contract checks if the minter supports IMETAGAME_CALLBACK_ID via SRC5 before dispatching callbacks. See Callbacks & Automation for integration details.
Data Structures
GameContextDetails
#[derive(Drop, Serde, Clone)]
pub struct GameContextDetails {
pub name: ByteArray,
pub description: ByteArray,
pub id: Option<u32>,
pub context: Span<GameContext>,
}GameContext
#[derive(Drop, Serde, Copy, Clone)]
pub struct GameContext {
pub name: felt252,
pub value: felt252,
}