Fetch candid from canister?

Hey, is it possible to fetch the candid file of a remote (running) canister A (different project) so I can import it somehow in my own motoko project and the appropriate actor for canister A will be generated with all the methods/types from the imported candid file in my project?


You can either grab it from https://www.ic.rocks/ or call the __get_candid_interface_tmp_hack function yourself.

Feature request for dfx: a fetch/install command that downloads candid files for remote canisters and generates bindings.


Is using __get_candid_interface_tmp_hack still the recommended way to get the candid of a public canister?

At this point in time, yes…

Note this function is only there for Motoko-based canister; for Rust canister; this function won’t be returned;

Unless they choose to do so.


The governance canister also does this:
And see this thread for more:

Is there a way to get candid from a Rust canister?

@Dustin To get the candid directly from the canister the rust canister developer currently has to provide a __get_candid_interface_tmp_hack method that serves the did file themselves. See the repo links in the last couple of posts above. (Motoko canisters do this by default.)

1 Like

Thanks @Ori. Just to make sure I understand correctly: Motoko canisters by default have their did available via __get_candid_interface_tmp_hack. Rust canisters have to explicitly make it available via adding a __get_candid_interface_tmp_hack. So if the owner of a Rust canister doesn’t declare the method, there is no way to get the candid directly from the canister?

Correct. There are other ways for rust developers to provide the candid (see GitHub - chenyan2002/ic-repl) but again they’d have to do this on their end.

At some point rust canisters could have this by default too, but there isn’t a direct binding for rust types so assumptions have to be made on how to map them. The didc command line tool https://github.com/dfinity/candid/tree/master/tools/didc now provides a binding this way though so it may be a step toward that default being enabled. @chenyan may have more info on this.

You could also check the canister directory here, where you can search by any canister id, did files are under the Canisters tab: https://k7gat-daaaa-aaaae-qaahq-cai.ic0.app
It’ll pick up the candid as above alongside candid provided in listings, so rust devs can add candid manually to a listing here if they prefer.

1 Like