Expand description
Reading a local development network out of the environment.
canton-devkit runs a Splice LocalNet — two participants and a super-validator — and exports everything an application needs to talk to it:
eval "$(canton-devkit localnet env demo)" # or: dpm localnet env demoThat sets a documented set of CANTON_* variables, and this module is the
one place in the SDK that knows their names. Config::from_env turns them
into a working gRPC configuration, so an application that would otherwise
carry endpoint and token plumbing for local development carries none:
let config = canton_core::Config::from_env()?;§The variables
| Variable | Meaning |
|---|---|
CANTON_GRPC_LEDGER_API_URL | gRPC Ledger API, scheme-less host:port |
CANTON_JSON_LEDGER_API_URL | JSON Ledger API, with an http(s):// scheme |
CANTON_<ROLE>_JWT | that role’s bearer token |
CANTON_<ALIAS>_PARTY | an on-ledger party id |
CANTON_INSTANCE, CANTON_SPLICE_VERSION | which network this is |
The unqualified URL variables point at the app-provider participant, the
usual target for an application. The other participants are reached by role:
CANTON_APP_USER_GRPC_LEDGER_API_URL, CANTON_SV_JWT, and so on.
Config::from_env_for takes the role name and applies the same
normalisation the exporter does (upper-case, - becomes _), so
"app-user" and "app_user" both work.
§Two things worth knowing
The URLs are nginx virtual-host names —
grpc-ledger-api.app-provider.demo.localhost — not plain hosts. The name is
what routes the request, so it has to survive into the :authority (gRPC) or
Host (HTTP) header rather than being resolved away by the caller. Passing
the URL through unchanged, as everything here does, is what keeps that true.
*.localhost resolves to loopback on macOS and on Linux with
systemd-resolved; where it does not, an /etc/hosts entry is the fix —
substituting 127.0.0.1 is not, because the vhost is then lost.
The gRPC URL has no scheme, because that is what a gRPC client dials.
Config accepts it that way.
§Anything else that sets the same names
Nothing here is devkit-specific beyond the variable names, and two generic
overrides come first for environments that are not a LocalNet at all:
CANTON_ENDPOINT and CANTON_TOKEN win over everything below them.
Functions§
- grpc_
endpoint - The gRPC Ledger API URL for
role, or the default participant’s whenroleisNone.CANTON_ENDPOINToverrides both. - instance
- The instance name the environment was exported from (
CANTON_INSTANCE). - json_
endpoint - The JSON Ledger API base URL for
role, or the default participant’s whenroleisNone. - party
- The on-ledger party id recorded under
alias— a role ("app-provider") or a name given to a party created later ("bob"). - splice_
version - The Splice release the network is running (
CANTON_SPLICE_VERSION). - token
- The bearer token for
role, or the default participant’s whenroleisNone.CANTON_TOKENoverrides both.