Skip to content

docs: add canister discovery, binding generation, and frontend development docs#338

Open
marc0olo wants to merge 2 commits intomainfrom
marc0olo/docs-bindings-env-variables
Open

docs: add canister discovery, binding generation, and frontend development docs#338
marc0olo wants to merge 2 commits intomainfrom
marc0olo/docs-bindings-env-variables

Conversation

@marc0olo
Copy link
Member

@marc0olo marc0olo commented Feb 4, 2026

Summary

Add documentation for canister discovery, binding generation, and frontend development workflows.

New Documentation

File Description
docs/concepts/canister-discovery.md How icp deploy injects PUBLIC_CANISTER_ID:* variables into all canisters; ic_env cookie mechanism for frontends; Rust/Motoko patterns for reading IDs
docs/concepts/binding-generation.md Generating TypeScript/Rust client bindings from Candid files using external tools

Updated Documentation

File Changes
docs/guides/local-development.md Added "Frontend Development" section covering asset canisters, dev server setup, and the two development approaches
docs/reference/environment-variables.md Added "Canister Runtime Environment Variables" section documenting PUBLIC_CANISTER_ID:* and IC_ROOT_KEY
docs/concepts/build-deploy-sync.md Fixed broken links; clarified env var injection step in deploy sequence
docs/tutorial.md Added link to Canister Discovery docs
docs/index.md, docs/concepts/index.md Added nav links to new concept docs
docs-site/astro.config.mjs Added sidebar entries for new pages

Updated Example

File Changes
examples/.../vite.config.ts Simplified to use icp network status --json for all environments; proper ic_root_key cookie format
examples/.../App.tsx Fixed IC_ROOT_KEY type to Uint8Array; cleaner implementation
examples/.../README.md Complete rewrite explaining the ic_env cookie mechanism

Key Technical Details

  • Cookie key is ic_root_key (lowercase); library returns IC_ROOT_KEY as Uint8Array
  • All canister IDs are injected into every canister in the environment
  • Rust: use ic_cdk::api::env_var_value() + Principal::from_text()
  • Motoko: no native env var support yet — use init arguments

@marc0olo marc0olo requested a review from a team as a code owner February 4, 2026 17:36
execSync(`icp network status -e ${environment} --json`, { encoding: "utf-8" })
);
const rootKey: string = networkStatus.root_key;
const proxyTarget: string = networkStatus.api_url;
Copy link
Member Author

@marc0olo marc0olo Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note:

  • the dev server wouldn't work correctly until we update the network status command to deliver the api_url


### Other Languages

The `didc` CLI generates bindings for various languages. See the [Candid repository](https://github.com/dfinity/candid) for available targets.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have a note somewhere that not all generated bindings will work well with icp-cli.

  • The target canister id needs to be fixed, or
  • the target canister id has to be fetched from the environment variables.


## Automatic Canister ID Injection

icp-cli solves this by automatically injecting canister IDs as environment variables during deployment.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
icp-cli solves this by automatically injecting canister IDs as environment variables during deployment.
icp-cli solves this by automatically injecting canister IDs as canister environment variables during deployment.

We must be careful to distinguish between "environment variables" that folks are used to and "canister environment variables"
Maybe this should link to the canister environment variables docs

).unwrap();
```

**Motoko** does not currently have native support for reading canister environment variables. Use init arguments instead — pass canister IDs when initializing the canister:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is correct - https://github.com/caffeinelabs/motoko/blob/a4cc7fe65bdc105fb453ba98de18beb8688b1e41/Changelog.md?plain=1#L167

There is an API to fetch a canister environment variable in motoko (caffeinelabs/motoko#5443)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants