Attribute Macro ic_cdk::import

source ·
#[import]
Expand description

Import another canister as a rust struct.

All public interfaces defined in corresponding candid file can be accessed through the annotated struct.

Example

You can specify the canister with it’s name.

Please be noted that this approach relies on the project organization by dfx.

During dfx build, the imported canister will be correctly resolved.

#[import(canister = "some_canister")]
struct SomeCanister;

Or you can specify both the canister_id and the candid_path.

#[import(canister_id = "abcde-cai", candid_path = "path/to/some_canister.did")]
struct SomeCanister;