In the C examples, why isn't there a Candid .DID file?

Hi,
Why isn’t there a candid .DID file for the example C program reverse?

Source files:

Can someone explain if the candid ILS is generated when compiled, or what the process really is, because I’m not finding a practical example of candid in use? And understanding it could help to let me use any language that compiles to wasm, which is not Rust or Motoko.

Thank you!

The candid .did files can be generated by the tooling for languages that have a binding, ie a clear mapping between types, Motoko has this, while Rust (and probably C) currently does not. But you can easily write a manual candid file for your canister no matter which language is used, you just declare the method signatures and types used in your public interface using candid syntax. There’s a very basic example of this process for a rust canister included here: Hello, World! Rust CDK Quick Start :: Internet Computer and more detail for general reference here: Supported types :: Internet Computer

2 Likes

Thanks for checking @Ori!

Following the introductory tutorial, I had no need to write a Candid file for the frontend, but looking at the documentation for Candid I learned that dfx build does a bit more for us (generates a javascript module, for example). It does mention that a description is required, but I haven’t created one!

While Motoko is taken care of, given the bindings, is this also truthy for javascript as I’ve exposed in the comment above?

The .did file is recommended but not required. Without the did file, dfx can still call the canister from CLI. But it is not easy for other canisters or frontend to call this canister, as we have tools to generate host language bindings from the did file. If you want to build the frontend for the reverse canister, you either need to provide the did file or write the JS binding by hand.

Here is the did file for the reverse canister, we probably should commit this to the repo.

service : {
  go : (text) -> (text);
}
3 Likes

Hi, I can’t promise that this tutorial is up-to-date, but the use of a Candid file is documented here https://sdk.dfinity.org/docs/developers-guide/work-with-languages.html:

Create a minimal interface description file

In a standard development workflow, running the dfx build command creates several files in the canisters output directory, including one or more Candid interface description ( .did ) files that handle type matching for the data types associated with a program’s functions.

For details about the syntax to use for different data types, see the Candid specification.

To create a Candid interface description file for this program:

  1. Open a terminal in the build directory you created for the reverse.c program source
  2. Create a new text file named reverse.did .
  3. Add a description of the go function.

For example:

service : {
  "go": (text) -> (text);
}

copy

  1. Save your changes and close the file to continue.
2 Likes

Ok, thanks for looking!

Ori’s response is mostly spot on, just minor additions:

  • Rust has a Candid library, and it support generating the .did file from your rust definitions.
  • For C, there isn’t even a Candid libary yet. So while you can of course write a .did file by hand, you’ll get Candid-encoded messages delivered to your canister. I hope someone writes a Candid library for C soon, though – don’t wait for DFINITY to do it :slight_smile:
2 Likes