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

**URL:** <https://forum.dfinity.org/t/when-is-import-canister-ic-canister-id-used/12618>\
**Category:** Developers\
**Created:** [May 1, 2022, 10:59pm UTC](https://forum.dfinity.org/t/when-is-import-canister-ic-canister-id-used/12618 "2022-05-01T22:59:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jzxchiang](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jzxchiang/32/2592_2.png) [@jzxchiang](https://forum.dfinity.org/u/jzxchiang)\
**Post date:** [May 1, 2022, 10:59pm UTC](https://forum.dfinity.org/t/when-is-import-canister-ic-canister-id-used/12618/1 "2022-05-01T22:59:03Z")

</div>

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](https://forum.dfinity.org/t/how-to-use-cowsay-project-in-my-project/6473/2) like:

```auto
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>"`?

---

<div class="post-metadata">

**Author:** ![nomeata](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/nomeata/32/733_2.png) [@nomeata](https://forum.dfinity.org/u/nomeata)\
**Post date:** [May 2, 2022, 7:46am UTC](https://forum.dfinity.org/t/when-is-import-canister-ic-canister-id-used/12618/2 "2022-05-02T07:46:07Z")

</div>

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](https://github.com/dfinity/motoko/blob/master/design/DFX-Interface.md#resolving-canister-types), 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.

---

<div class="post-metadata">

**Author:** ![jzxchiang](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jzxchiang/32/2592_2.png) [@jzxchiang](https://forum.dfinity.org/u/jzxchiang)\
**Post date:** [May 3, 2022, 12:56am UTC](https://forum.dfinity.org/t/when-is-import-canister-ic-canister-id-used/12618/3 "2022-05-03T00:56:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jzxchiang](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jzxchiang/32/2592_2.png) [@jzxchiang](https://forum.dfinity.org/u/jzxchiang)\
**Post date:** [May 3, 2022, 12:57am UTC](https://forum.dfinity.org/t/when-is-import-canister-ic-canister-id-used/12618/4 "2022-05-03T00:57:23Z")

</div>

> 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?

---

<div class="post-metadata">

**Author:** ![nomeata](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/nomeata/32/733_2.png) [@nomeata](https://forum.dfinity.org/u/nomeata)\
**Post date:** [May 3, 2022, 7:10am UTC](https://forum.dfinity.org/t/when-is-import-canister-ic-canister-id-used/12618/5 "2022-05-03T07:10:19Z")

</div>

> [@jzxchiang](#):
>
> Gotcha. Does that mean it’s best not to use this import syntax at all, whether locally or in production?

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🙂

> [@jzxchiang](#):
>
> Interesting, do you happen to have a link to this?

> <https://github.com/dfinity/interface-spec/commit/51913bfb18fd85a28e5b35186b328704eb9136da>
>
> Spec out #279 
> 
> Add \`/canisters/\<canister\_id\>/metadata/\<name\>\` in the state tr…ee, so that custom sections can be downloaded in a certified way. Custom section \`icp:public \<name\>\` is publicly accessible. \`icp:private \<name\>\` can only be read by the controllers of the canister. 
> 
> There are several important use cases:
> 1) We need a certified way to fetch the Candid interface from the running canister to support various generic tools, such as dfx, Candid UI and ic.rocks.
> 2) To support safe upgrade and prevent data loss, we need to fetch the Candid interface and stable variable types from the running canister to check for subtyping. The stable variable types are internal and should only be accessible by the controller of the canister.
> 3) It can be used by canister developers to provide a mock interface so that local replica can use the mocked interface to talk to external services.

---

<div class="post-metadata">

**Author:** ![kentosugama](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/kentosugama/32/6262_2.png) [@kentosugama](https://forum.dfinity.org/u/kentosugama)\
**Post date:** [October 4, 2023, 7:32pm UTC](https://forum.dfinity.org/t/when-is-import-canister-ic-canister-id-used/12618/6 "2023-10-04T19:32:39Z")

</div>

Commenting this here in case anyone is reading in the future: [Import canister QOL](https://forum.dfinity.org/t/import-canister-qol/23509)
