| title | Binding Generation |
|---|---|
| description | Generate type-safe client code from Candid interface files to call canister methods with full type checking. |
Understanding and using type-safe client code for calling canisters.
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 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.
icp-cli focuses on deployment — use these dedicated tools to generate bindings:
| Language | Tool | Documentation |
|---|---|---|
| TypeScript/JavaScript | @icp-sdk/bindgen |
js.icp.build/bindgen |
| Rust | candid crate |
docs.rs/candid |
| Other languages | didc CLI |
github.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.
Use @icp-sdk/bindgen to generate TypeScript bindings from Candid files. See the @icp-sdk/bindgen documentation for usage and build tool integration.
The candid crate provides Candid serialization and code generation macros. See the candid crate documentation.
The didc CLI generates bindings for various languages. See the Candid repository for available targets.
- Canister Discovery — How canisters find each other's IDs
- Local Development — Development workflow