Skip to content

safeGetCanisterEnv

safeGetCanisterEnv<T>(options): undefined | CanisterEnv & T

Defined in: packages/agent/src/canister-env/index.ts:155

Experimental

Safe version of getCanisterEnv that returns undefined instead of throwing errors.

T = Record<string, never>

GetCanisterEnvOptions = {}

The options for loading the asset canister environment variables

undefined | CanisterEnv & T

The environment variables for the asset canister, or undefined if any error occurs

The Canister Environment Guide for more details on how to use the canister environment in a frontend application

// in a browser environment with valid cookie
const env = safeGetCanisterEnv();
console.log(env); // { IC_ROOT_KEY: Uint8Array, ... }
// in a Node.js environment
const env = safeGetCanisterEnv();
console.log(env); // undefined
// in a browser without the environment cookie
const env = safeGetCanisterEnv();
console.log(env); // undefined