Skip to content
dojo-events logo

Dojo.js Events & Token Tracking

dojo-events

Use when subscribing to game events and tracking tokens in dojo.js. Triggers: subscribe events, game events, token balance, event query, achievements, event subscription, onTokenBalanceUpdated, activity tracking

SKILL.md

Full skill instructions

Dojo.js Events & Token Tracking

When to Use

Use this skill when:

  • Subscribing to game events
  • Tracking token balances
  • Monitoring token transfers
  • Tracking achievements and activities

Event Subscriptions

Subscribe to Event Messages

import { ToriiQueryBuilder } from "@dojoengine/​sdk";
import { useDojoSDK } from "@dojoengine/​sdk/​react";

const { sdk } = useDojoSDK();

const [initialEvents, subscription] = await sdk.subscribeEventQuery({
    query: new ToriiQueryBuilder<typeof schema>()
        .addEntityModel("game-GameEvent")
        .withLimit(100),
    callback: ({ data, error }) => {
        if (error) {
            console.error("Event error:", error);
            return;
        }
        console.log("New event:", data);
    }
});

// Process initial events
initialEvents.items.forEach(event => {
    console.log(event.models.game.GameEvent);
});

// Cleanup
subscription.cancel();

Get Event Messages (One-time)

const events = await sdk.getEventMessages({
    query: new ToriiQueryBuilder<typeof schema>()
        .addEntityModel("game-PlayerAction")
        .addOrderBy("game-PlayerAction.timestamp", "Desc")
        .withLimit(50)
});

Token Balance Tracking

Subscribe to Token Balances

const [balances, subscription] = await sdk.subscribeTokenBalance({
    // Contract addresses must be full hex strings with 0x prefix
    contractAddresses: ["0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"],
    accountAddresses: [playerAddress],
    callback: (balance) => {
        console.log("Balance updated:", balance.balance);
    }
});

// Initial balances
balances.items.forEach(b => {
    console.log(`Token: ${b.token_id}, Balance: ${b.balance}`);
});

Get Token Balances

const balances = await sdk.getTokenBalances({
    contractAddresses: ["0x..."],
    accountAddresses: [playerAddress],
    pagination: { limit: 100 }
});

Track Balance Updates Only

const subscription = await sdk.onTokenBalanceUpdated({
    contractAddresses: ["0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"],
    accountAddresses: [playerAddress],
    // Empty array for all tokens (ERC20); for ERC721 use specific IDs: ["0x1", "0x2"]
    tokenIds: [],
    callback: (balance) => {
        updateUI(balance);
    }
});

Token Transfer Tracking

const [transfers, subscription] = await sdk.subscribeTokenTransfer({
    contractAddresses: ["0x..."],
    accountAddresses: [playerAddress],
    callback: (transfer) => {
        console.log(`Transfer: ${transfer.from} -> ${transfer.to}`);
    }
});

Token Queries

// Get tokens
const tokens = await sdk.getTokens({
    contractAddresses: ["0x..."],
    pagination: { limit: 100 }
});

// Get token contracts
const contracts = await sdk.getTokenContracts({
    contractTypes: ["ERC20", "ERC721"]
});

Achievement Tracking

// Get achievements
const achievements = await sdk.getAchievements({
    worldAddresses: [worldAddress],
    namespaces: ["game"]
});

// Get player achievements
const playerAchievements = await sdk.getPlayerAchievements({
    playerAddresses: [playerAddress]
});

// Subscribe to achievement progress
const subscription = await sdk.onAchievementProgressionUpdated({
    worldAddresses: [worldAddress],
    playerAddresses: [playerAddress],
    callback: (progression) => {
        console.log("Achievement progress:", progression);
    }
});

Activity Tracking

// Get activities
const activities = await sdk.getActivities({
    world_addresses: [worldAddress],
    namespaces: ["game"],
    caller_addresses: [playerAddress]
});

// Subscribe to activities
const subscription = await sdk.onActivityUpdated(
    [worldAddress],
    ["game"],
    [playerAddress],
    (activity) => {
        console.log("New activity:", activity);
    }
);

Aggregations

// Get aggregated data
const aggregations = await sdk.getAggregations({
    aggregator_ids: ["total_players", "total_games"],
    pagination: { limit: 10 }
});

// Subscribe to aggregation updates
const subscription = await sdk.onAggregationUpdated(
    ["total_players"],
    null,
    (aggregation) => {
        console.log("Aggregation updated:", aggregation);
    }
);

Update Subscriptions

// Update token balance subscription
await sdk.updateTokenBalanceSubscription({
    subscription,
    contractAddresses: newContracts,
    accountAddresses: newAccounts,
    tokenIds: []
});

// Update entity subscription
await sdk.updateEntitySubscription(
    subscription,
    newClause
);

React Effect Atoms

For complex async state:

import { createEventQueryAtom, createEventUpdatesAtom } from "@dojoengine/​react/​effect";

// One-time event query
const eventsAtom = createEventQueryAtom(runtime, query);

// Live event updates
const updatesAtom = createEventUpdatesAtom(runtime, clauses);

// Combined query + updates
const liveEventsAtom = createEventQueryWithUpdatesAtom(runtime, query, clauses);

Common Pitfalls

  1. Subscription cleanup: Always cancel subscriptions when component unmounts
  2. Contract addresses: Must be padded hex strings with 0x prefix
  3. Token IDs: Format depends on token type (ERC20 vs ERC721)
  4. Rate limiting: Avoid creating too many subscriptions
  5. Callback errors: Wrap callbacks in try-catch to prevent unhandled errors

More skills from majiayu000

xiaohongshu logo
majiayu000/claude-arsenal

xiaohongshu

xiaohongshu

286 148
View
agent-task-conductor logo
majiayu000/claude-skill-registry

agent-task-conductor

Conduct multi-agent task orchestration and workflow coordination.

663 1
View
conductor-setup logo
majiayu000/claude-skill-registry

conductor-setup

Initialize project with Conductor artifacts (product definition,

663 1
View
animation-designer logo
majiayu000/claude-skill-registry

animation-designer

Expert in web animations, transitions, and motion design using Framer Motion and CSS

663 1
View
diagramming logo
majiayu000/claude-skill-registry

diagramming

Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...

663 1
View
h3-pg logo
majiayu000/claude-skill-registry-data

h3-pg

PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.

23 1
View
conductor-development logo
majiayu000/claude-skill-registry

conductor-development

Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...

663 1
View
conductor-status logo
majiayu000/claude-skill-registry

conductor-status

Display project status, active tracks, and next actions

663 1
View
dockerization logo
majiayu000/claude-skill-registry

dockerization

Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.

663 1
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View