docs: Candid interface guide#11
Conversation
Cover the Candid type system, .did file structure, type mapping between Motoko/Rust/JavaScript, generating .did files for Rust canisters, safe interface upgrades via subtyping rules, and Candid tooling (didc, Candid UI).
marc0olo
left a comment
There was a problem hiding this comment.
Review: Candid Interface
Must fix
None.
Suggestions
-
icskillsfrontmatter is empty — The page covers Candid, which is cross-cutting.icskills: [multi-canister]could fit since Candid underpins inter-canister communication. Optional. -
JS SDK
createActorimport path — The example imports from"./declarations/my_canister", which is correct for icp-cli-generated projects. A brief note that these declarations are auto-generated duringicp buildwould help readers understand where the import comes from. The content brief explicitly mentions@icp-sdk/core— the current example uses the declarations path instead. Both approaches are valid, but clarifying when to use which would be helpful. -
opt TJavaScript representation — The table shows[value] | []foropt Tin JavaScript. Technically correct at the IDL level, but in practice developers often usefromNullable()/toNullable()helpers from@dfinity/utils. A brief mention would be helpful but is not a blocker. -
Rust recipe version
v3.2.0— The version in theicp.yamlexample is hardcoded. Templates in.sources/icp-cli-templates/usev3.1.0. Verify thatv3.2.0actually exists, or usev3.1.0(or a placeholder) instead. -
generate-didcrate — Mentioned as an alternative tocandid-extractor. Worth verifying that it is actively maintained on crates.io, since it is not an official DFINITY tool. If uncertain, flag with<!-- Needs human verification: is generate-did actively maintained? -->. -
Candid UI canister ID —
a4gq6-oaaaa-aaaab-qaa4q-caiis the well-known Candid UI canister. Looks correct but worth a quick sanity check.
Verified
- All internal links resolve to existing files (
canisters.md,candid-spec.md,onchain-calls.md,offchain-calls.md,binding-generation.md) docs/concepts/canisters.mdhas a### Query callsheading — anchor matches- Zero
dfxreferences in the entire diff - CLI syntax
icp canister callverified against.sources/icp-cli/docs/reference/cli.md export_candid!macro usage verified against.sources/portal/and.sources/examples/- Candid subtyping rules match portal source material (all 6 rules correct)
- Type mapping table checked against Candid specification — accurate
- Record/variant examples in Motoko and Rust are correct
icp.yamlRust recipe format matches.sources/icp-cli-recipes/candid-extractorworkflow correctdidcCLI command table correct- Content brief fully covered (type system, service definitions, type mapping, Candid generation, JS actor creation, subtyping rules)
- Source material was consulted (all 3 portal Candid files + Rust generating-candid)
- No
.mdx/JSX, plain.md, frontmatter complete - Page follows Diataxis how-to guide format: orient → explain → examples → next steps
- Good scanability: clear headings, code examples, tables
marc0olo
left a comment
There was a problem hiding this comment.
Review: Candid Interface
Must fix
None.
Suggestions
-
icskillsfrontmatter is empty — The page covers Candid, which is cross-cutting.icskills: [multi-canister]could fit since Candid underpins inter-canister communication. Optional. -
JS SDK
createActorimport path — The example imports from"./declarations/my_canister", which assumes pre-generated declarations. A brief note on how these declarations are produced (e.g.,@icp-sdk/bindgenfor JS/TS, ordidc bindgenerically) would help readers understand where the import comes from. The content brief also mentions@icp-sdk/core— clarifying the relationship between the SDK and the declarations would be valuable. -
opt TJavaScript representation — The table shows[value] | []foropt Tin JavaScript. Technically correct at the IDL level, but in practice developers often usefromNullable()/toNullable()helpers from@dfinity/utils. A brief mention would be helpful but is not a blocker. -
Rust recipe version
v3.2.0— The version in theicp.yamlexample is hardcoded. Templates in.sources/icp-cli-templates/usev3.1.0. Verify thatv3.2.0actually exists, or usev3.1.0(or a placeholder) instead. -
generate-didcrate — Mentioned as an alternative tocandid-extractor. Worth verifying that it is actively maintained on crates.io, since it is not an official DFINITY tool. If uncertain, flag with<!-- Needs human verification: is generate-did actively maintained? -->. -
Candid UI canister ID —
a4gq6-oaaaa-aaaab-qaa4q-caiis the well-known Candid UI canister. Looks correct but worth a quick sanity check.
Verified
- All internal links resolve to existing files (
canisters.md,candid-spec.md,onchain-calls.md,offchain-calls.md,binding-generation.md) docs/concepts/canisters.mdhas a### Query callsheading — anchor matches- Zero
dfxreferences in the entire diff - CLI syntax
icp canister callverified against.sources/icp-cli/docs/reference/cli.md export_candid!macro usage verified against.sources/portal/and.sources/examples/- Candid subtyping rules match portal source material (all 6 rules correct)
- Type mapping table checked against Candid specification — accurate
- Record/variant examples in Motoko and Rust are correct
icp.yamlRust recipe format matches.sources/icp-cli-recipes/candid-extractorworkflow correctdidcCLI command table correct- Content brief fully covered (type system, service definitions, type mapping, Candid generation, JS actor creation, subtyping rules)
- Source material was consulted (all 3 portal Candid files + Rust generating-candid)
- No
.mdx/JSX, plain.md, frontmatter complete - Page follows Diataxis how-to guide format: orient → explain → examples → next steps
- Good scanability: clear headings, code examples, tables
Updated: corrected suggestion 2 regarding declaration generation (not handled by icp-cli build).
- Clarify JS SDK declaration generation: add @icp-sdk/bindgen and didc bind as explicit generation steps, mention @icp-sdk/core as runtime - Add opt T JavaScript tip: fromNullable()/toNullable() from @dfinity/utils - Drop generate-did crate (third-party wrapper around candid-extractor)
|
Feedback addressed:
|
- Fix bindgen invocation: --did-file/--out-dir (not --canister) - Update sync comment to reference .sources/candid, .sources/motoko, and .sources/cdk-rs as verification sources
Summary
How-to guide for defining and using Candid interfaces. Covers:
.didfile format: service definitions, named types, init arguments.sources/candid(spec),.sources/motoko(IDL-Motoko.md), and.sources/cdk-rs.didfiles: automatic for Motoko,export_candid!+candid-extractorfor Rusticp canister call), JavaScript (@icp-sdk/core+@icp-sdk/bindgen), inter-canisterreserved)didcCLI command reference, Candid UIopt Ttip (fromNullable/toNullablefrom@dfinity/utils)Sync recommendation
Informed by
dfinity/portal—docs/building-apps/interact-with-canisters/candid/(3 files) anddocs/building-apps/developer-tools/cdks/rust/generating-candid.mdx. Type mappings verified against.sources/candid,.sources/motoko, and.sources/cdk-rs.