When is `import Canister "ic:<canister-id>"` used?

I couldn’t find any good documentation about it.

I know that canisters can do import Canister "canister:<name>" to import another canister from the same dfx.json project. If the canister isn’t specified in the dfx.json, then the programmer can write something like:

actor {
    public func main() : async Text {
        let cowsay = actor(“7igbu-3qaaa-aaaaa-qaapq-cai”): actor { cowsay: (Text) -> async Text };
        return await cowsay.cowsay(“hello”);
    };
};

But when is it useful (if ever) to do import Canister "ic:<canister-id>"?

1 Like

I think it’s not fully supported by the full toolchain. The vision was that if you import Canister "ic:7igbu-3qaaa-aaaaa-qaapq-cai" then dfx would fetch the candid interface from the Internet Computer and thus give you the right type directly, so you wouldn’t have to write the type in your code (and hope you got it right).

The motoko side of this feature was there for a long while now, but we only decided on the “official” system-level protocol for storing and fetching that interface with the canister very recently, which was blocking this, and I don’t think the dfx devs have started implementing this feature yet.

Gotcha. Does that mean it’s best not to use this import syntax at all, whether locally or in production?

we only decided on the “official” system-level protocol for storing and fetching that interface with the canister very recently, which was blocking this

Interesting, do you happen to have a link to this?

I think it simply doesn’t work yet, so yes :-).

It is ok to use of you’d use a different build system than dfx that provides the Candid files for these canisters to the motoko compiler. But to my knowledge nobody has written such a build system before. Although I wouldn’t be surprised if the Motoko Playground, which is in a way a build system for Motoko separate from dfx, would implement this feature first … pinging @chenyan :slight_smile:

2 Likes

Commenting this here in case anyone is reading in the future: Import canister QOL

1 Like