Skip to content

switchNetworkEnvironment

Switch the active network environment, recomputing the active network set.

When environment is omitted the current environment is toggled. The RPC client is rebuilt lazily by config.getRpc per environment, so no transport is touched here — only reactive state is updated.

Import

ts
import { switchNetworkEnvironment } from "@0xcurvy/curvy-sdk/actions";

Usage

ts
await switchNetworkEnvironment();                          // toggle
await switchNetworkEnvironment({ environment: "testnet" });

Signature

ts
function switchNetworkEnvironment(parameters?: SwitchNetworkEnvironmentParameters): Promise<NETWORK_ENVIRONMENT_VALUES>

Returns

Promise<"mainnet" | "testnet">

The action resolves or returns the value shown in the signature.

Parameters

environment

  • Type: "mainnet" | "testnet"
  • Required: no

Target environment. When omitted, toggles the current environment.

ts
const result = await switchNetworkEnvironment({
  environment, 
});

config

  • Type: CurvyConfig
  • Required: no

Curvy config to use. Defaults to the ambient config.

ts
const result = await switchNetworkEnvironment({
  config, 
});

Errors

  • when no networks match the target environment after filtering.
  • when the filtered networks mix mainnet and testnet.
  • Config guide
  • getNetworks — Get the known networks, optionally narrowed by a filter.
  • getNetwork — Get exactly one network matching the filter, throwing if zero or many match.
  • watchEnvironment — Subscribe to changes of the config's network environment.
  • ensResolveCurvyId — Resolve a Curvy handle to an on-chain address via ENS for the active environment.

Source

packages/@0xcurvy/sdk/src/actions/networks/switchNetworkEnvironment.ts