Skip to content

Candid Parser

A powerful example demonstrating dynamic canister method calls by parsing Candid interface strings at runtime. Perfect for building explorers, developer tools, or any application that needs to interact with canisters without pre-generated type definitions.

  • CandidDisplayReactor for dynamic canister interactions with display transformations
  • Runtime Candid interface string parsing
  • queryDynamic for one-shot query calls
  • callDynamic for one-shot update calls
  • Automatic bigint → string conversion (no manual serialization needed!)
  • JSON argument parsing with display types
  • Error handling with user-friendly feedback
import { CandidDisplayReactor } from "@ic-reactor/candid"
import { ClientManager } from "@ic-reactor/core"
// Create a client manager
const clientManager = new ClientManager({
queryClient: new QueryClient(),
})
// Create a CandidDisplayReactor instance
// It automatically converts bigint → string, Principal → string
const reactor = new CandidDisplayReactor({
canisterId: "ryjl3-tyaaa-aaaaa-aaaba-cai", // ICP Ledger
clientManager,
})
// Define your Candid interface as a string
const candidInterface = `service : {
icrc1_name : () -> (text) query;
icrc1_symbol : () -> (text) query;
icrc1_balance_of : (record { owner : principal }) -> (nat) query;
}`
// Execute a dynamic query - result is already display-friendly!
const result = await reactor.queryDynamic({
functionName: "icrc1_name",
candid: candidInterface,
args: [],
})
console.log(result) // "Internet Computer"
// Query balance with display types
const balance = await reactor.queryDynamic({
functionName: "icrc1_balance_of",
candid: candidInterface,
args: [{ owner: "aaaaa-aa" }], // Principal as string!
})
console.log(balance) // "1000000" (string, not bigint!)
  • Canister Explorers: Build tools that can interact with any canister by pasting its Candid interface
  • Developer Debugging: Test canister methods without setting up full type definitions
  • Admin Dashboards: Create dynamic admin panels for managing multiple canisters
  • Learning Tools: Help developers understand Candid interfaces interactively