Skip to content

dfinity/icp-js-bindgen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

114 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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.