Generate TypeScript bindings for Candid
npm install @icp-sdk/bindgenGenerate modern TypeScript bindings for Internet Computer (IC) canisters from Candid .did files.
The tool can be used in three ways:
- CLI
- Vite plugin
- Library
> Note: Generated code references @icp-sdk/core (agents, candid, principals). Install it in your app if you plan to compile/run the generated code. See js.icp.build/core.
``bash`
npm i -D @icp-sdk/bindgen
Generate bindings from a hello_world.did file into src/bindings:
`ts
// vite.config.ts
import { defineConfig } from 'vite';
import { icpBindgen } from '@icp-sdk/bindgen/plugins/vite';
export default defineConfig({
plugins: [
icpBindgen({
didFile: './hello_world.did',
outDir: './src/bindings',
}),
],
});
`
Use the generated client:
`ts
import { createActor } from './bindings/hello_world';
const actor = createActor('your-canister-id');
const greeting = await actor.greet('World');
``
For more info, see the docs.
Contributions are welcome! Please see the contribution guide for more information.
This project is licensed under the Apache-2.0 license.