Skip to content

getNetwork

Get the connected account's currently active network.

Usage

ts
const network = await Turing.getNetwork();

Parameters

This method takes no parameters.

Returns

ts
interface GetNetworkResponse {
  network: "tbc" | "btc" | "eth" | "bnb" | "all";
  type: "mainnet" | "testnet";
}
FieldTypeDescription
network"tbc" | "btc" | "eth" | "bnb" | "all"Active chain. "all" means the user is in the wallet's "all networks" view and has not selected a specific chain.
type"mainnet" | "testnet"Mainnet / testnet. Only tbc may be "testnet"; all other chains are always "mainnet".

Error Handling

ErrorCause
User not connectedTuring.connect() has not been called, or the user has disconnected.
ts
try {
  const info = await Turing.getNetwork();
  console.log(info);
} catch (error) {
  console.error("Failed to get network:", error);
}

Subscribe to changes

When the network is switched inside the wallet, the dapp receives a TuringNetworkChanged event with the new network, so there is no need to poll getNetwork().

ts
window.addEventListener("TuringNetworkChanged", (event) => {
  const { network } = event.detail;
  // `network` has the same shape as Turing.getNetwork()
});
ts
interface TuringNetworkChangedDetail {
  network: GetNetworkResponse;
}

The event only fires while the dapp is connected, and only on changes after connect() (the initial network can be obtained via Turing.getNetwork()).