Skip to main content

Module localnet

Module localnet 

Source
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 demo

That 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

VariableMeaning
CANTON_GRPC_LEDGER_API_URLgRPC Ledger API, scheme-less host:port
CANTON_JSON_LEDGER_API_URLJSON Ledger API, with an http(s):// scheme
CANTON_<ROLE>_JWTthat role’s bearer token
CANTON_<ALIAS>_PARTYan on-ledger party id
CANTON_INSTANCE, CANTON_SPLICE_VERSIONwhich 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 namesgrpc-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 when role is None. CANTON_ENDPOINT overrides 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 when role is None.
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 when role is None. CANTON_TOKEN overrides both.