Candid to JS
Compiles Candid strings to idlFactory and init exports for HttpAgent.
The @ic-reactor/parser package is a high-performance WASM-based parser for the DFINITY Candid language. It compiles Candid interface definitions (.did files) into JavaScript and TypeScript bindings directly in the browser or Node.js environment.
While @ic-reactor/candid handles the fetching and interaction logic, this package provides the raw parsing power.
didjs canister to compile Candid.Candid to JS
Compiles Candid strings to idlFactory and init exports for HttpAgent.
Candid to TS
Generates full TypeScript type definitions from Candid.
WASM Power
Built with Rust and compiled to WebAssembly for performance.
npm install @ic-reactor/parserImport the parser and use the synchronous methods didToJs or didToTs.
import { didToJs, didToTs } from "@ic-reactor/parser"
const candid = "service:{icrc1_name:()->(text) query;}"
// Convert to JavaScript (idlFactory)const js = didToJs(candid)console.log(js)// Output:// export const idlFactory = ({ IDL }) => {// return IDL.Service({ 'icrc1_name' : IDL.Func([], [IDL.Text], ['query']) });// };// export const init = ({ IDL }) => { return []; };
// Convert to TypeScript definitionsconst ts = didToTs(candid)console.log(ts)// Output:// import type { Principal } from '@icp-sdk/core/principal';// ...// export interface _SERVICE { 'icrc1_name' : ActorMethod<[], string> }// ...This package is designed to work seamlessly with @ic-reactor/candid. When you initialize a CandidAdapter or CandidReactor, it can automatically use this parser if it’s installed/loaded.
import { createCandidAdapter } from "@ic-reactor/core"
const adapter = createCandidAdapter({ agentManager })
// This internally loads the WASM from @ic-reactor/parser if availableawait adapter.initializeParser()
const { idlFactory } = adapter.parseDidToJs("service:{}")