Skip to content

dojo.c: Complete Dojo Client SDK

dojo.c is the comprehensive client library that powers all Dojo SDKs. Written in Rust, it provides everything you need for Dojo game development: world state queries via Torii, account management, transaction execution, and real-time subscriptions that work consistently across all platforms.

Implementation Architecture

Rather than implementing blockchain logic separately in each SDK, all Dojo integrations build on this single foundation:

  • Unity SDK uses dojo.c via C# P/Invoke
  • JavaScript SDK uses dojo.c compiled to WebAssembly
  • Unreal Engine integrates dojo.c through C++ bindings
  • Custom integrations can use dojo.c directly

This ensures consistent behavior, shared bug fixes, and optimal performance across all platforms. Implementing in Rust provides the following advantages:

  • Memory Safety: Eliminates classes of bugs (buffer overflows, use-after-free, etc.)
  • Performance: Zero-cost abstractions compile to optimal machine code
  • Concurrency: Safe async/await and threading without data races
  • Ecosystem: Built on battle-tested Rust libraries (tokio, serde, starknet-rs)
  • Cross-Platform: Single codebase compiles to all target platforms
dojo.c Repository (Rust Implementation)
├── Core Rust Logic (types.rs, utils.rs, constants.rs)
├── Conditional Compilation:
│   ├── Native Target → C Bindings (cbindgen)
│   └── WASM Target → JavaScript Bindings (wasm-bindgen)
└── Generated Outputs:
    ├── libdojo_c.{so,dylib,dll} + dojo.h
    └── dojo_c.js + dojo_c.wasm

The key insight: two interfaces, one implementation. Both C and WASM APIs share identical Rust core logic, ensuring consistency.

The two interfaces are designed for different use cases:

C Bindings API

Target: Native platform integrations, custom SDKs, maximum performance

  • Style: Procedural C functions with callback-based async operations
  • Use Cases: Building Unity/Unreal plugins, system-level integrations
  • Memory Management: Manual with explicit cleanup functions
  • Threading: Callback-driven with internal runtime management

WASM JavaScript API

Target: Web applications, Node.js, rapid prototyping

  • Style: Modern async/await with object-oriented design
  • Use Cases: Browser games, web apps, Node.js backends, testing
  • Memory Management: Automatic garbage collection
  • Threading: Promise-based with native async support

What You Get

dojo.c is a "batteries included" SDK that bundles everything needed for Dojo game development:

Torii Client (Primary Focus)

  • Entity Queries: Fetch world state with powerful filtering and pagination
  • Real-time Subscriptions: Subscribe to entity changes and events
  • Transaction Monitoring: Track transaction status and confirmations

Integrated Account Management

  • Controller Accounts: Session-based accounts with policy-restricted permissions
  • Burner Accounts: Disposable accounts funded by a master account
  • Direct Accounts: Full control accounts for advanced use cases

Built-in Starknet Provider

  • Transaction Execution: Submit transactions directly without separate RPC setup
  • Contract Calls: Query contract view functions
  • Chain Operations: Handle nonces, block IDs, and transaction waiting

Asset & Token Operations

  • Token Queries: Fetch ERC20/721/1155 token information
  • Balance Tracking: Monitor token balances across accounts
  • Real-time Updates: Subscribe to token and balance changes

Event & Message System

  • Event Subscriptions: Listen to Starknet events and Dojo model changes
  • Message Publishing: Send messages through the Dojo messaging system
  • Transaction History: Query historical transactions and events

Choosing the Right API

FactorC BindingsWASM JavaScript
PerformanceMaximumVery Good
Integration EffortHigherLower
Platform SupportNative OnlyWeb + Node.js
Development SpeedSlowerFaster
Memory ControlFullAutomatic
DebuggingNative ToolsBrowser DevTools

Use Case Decision Guide

🎯 Choose C Bindings when you need:
  • Native Integration: Unity plugins, Unreal Engine modules, or desktop applications
  • Maximum Performance: Every microsecond matters for your game
  • Platform SDK Development: Creating bindings for new languages/platforms
  • System-Level Control: Direct memory management, custom threading models
🚀 Choose WASM JavaScript when you need:
  • Web Games: Browser-based Dojo games with real-time world state
  • Rapid Prototyping: Quick development with familiar JavaScript patterns
  • Node.js Backends: Server-side game logic, bots, APIs
  • Rich Debugging: Browser DevTools, source maps, hot reload

Integration Examples

Unity Integration Example:
[DllImport("libdojo_c", CallingConvention = CallingConvention.Cdecl)]
public static extern ResultToriiClient client_new(CString torii_url, FieldElement world);
Node.js Integration Example:
const { ToriiClient } = require('./pkg/dojo_c');
const client = await new ToriiClient(config);

dojo.c provides everything you need for Dojo game development in one comprehensive package. Whether you're building Unity games, web applications, or custom integrations, it delivers consistent, reliable blockchain interaction with the convenience of an integrated Torii client, account management, and Starknet provider.

Next Steps