JSPM

  • Created
  • Published
  • Downloads 3058
  • Score
    100M100P100Q125353F
  • License Apache-2.0

Generate TypeScript bindings for Candid

Package Exports

  • @icp-sdk/bindgen
  • @icp-sdk/bindgen/core
  • @icp-sdk/bindgen/plugins/vite

Readme

ICP JS SDK Bindgen

Generate modern TypeScript bindings for Internet Computer (IC) canisters from Candid .did files.

The tool can be used in three ways:

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.

Install

npm i -D @icp-sdk/bindgen

Quick start (Vite)

Generate bindings from a hello_world.did file into src/bindings:

// 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:

import { createActor } from './bindings/hello_world';

const actor = createActor('your-canister-id');
const greeting = await actor.greet('World');

For more info, see the docs.

Contributing

Contributions are welcome! Please see the contribution guide for more information.

License

This project is licensed under the Apache-2.0 license.