Skip to content
ICP CLI
Feedback welcome! Report issues on GitHub, ask questions on the Forum, or chat with us on Discord.

Binding Generation

Understanding and using type-safe client code for calling canisters.

What Are Bindings?

Bindings are generated code that provides type-safe access to canister methods. They’re created from Candid interface files (.did), which define a canister’s public API.

Candid Interface Files

Candid is the interface description language for the Internet Computer. A .did file defines the public methods and types a canister exposes — it’s the contract between a canister and its callers.

.did files can be:

  • Manually authored — Recommended for stable APIs where backward compatibility matters
  • Generated from code — Convenient during development, but review before publishing

For Candid syntax and best practices, see the Candid specification.

Generating Client Bindings

icp-cli focuses on deployment — use these dedicated tools to generate bindings:

LanguageToolDocumentation
TypeScript/JavaScript@icp-sdk/bindgenjs.icp.build/bindgen
Rustcandid cratedocs.rs/candid
Other languagesdidc CLIgithub.com/dfinity/candid

Note: Generated bindings typically hardcode a canister ID or require one at initialization. With icp-cli, canister IDs differ between environments. You can look up IDs with icp canister status <name> -i, or read them from canister environment variables at runtime. See Canister Discovery for details.

TypeScript/JavaScript

Use @icp-sdk/bindgen to generate TypeScript bindings from Candid files. See the @icp-sdk/bindgen documentation for usage and build tool integration.

Rust

The candid crate provides Candid serialization and code generation macros. See the candid crate documentation.

Other Languages

The didc CLI generates bindings for various languages. See the Candid repository for available targets.

See Also

Browse all documentation →