Skip to main content

Generating Candid files for Rust canisters


In versions of the Rusk CDK v0.11.0 and higher, the Candid export workflow has been changed. You can call the ic_cdk::export_candid!() macro to enable the Candid export behavior, then use the candid-extractor to extract the Candid from the canister's Wasm.


  • Step 1: Upgrade ic-cdk dependency to v0.11.0 or higher:

# Cargo.toml
ic-cdk = "0.11.0"
cargo install candid-extractor

With cargo-binstall you can install the prebuilt binary without waiting for compilation:

cargo binstall candid-extractor


  • Step 1. Call the export_candid macro at the end of your file:

fn hello(name: String) -> String {
format!("Hello, {}!", name)

fn world(name: String) -> String {
format!("World, {}!", name)

// Enable Candid export
  • Step 2: Compile the Canister Wasm module.

cargo build --release --target wasm32-unknown-unknown --package <CANISTER>

The Wasm module will be at:

  • Step 3: Extract candid from the Wasm module and save to a file:

candid-extractor target/wasm32-unknown-unknown/release/<CANISTER>.wasm > <CANISTER>.did