Actions
Switch Network
The switchNetwork action changes the currently selected network that the dApp Kit client is
configured to use.
Network switching only affects your dApp's client connection. The wallet itself is not affected by this change, and wallets are not notified when the network changes in the dApp.
Usage
import { createDAppKit } from '@mysten/dapp-kit-core';
import { SuiGrpcClient } from '@mysten/sui/grpc';
const GRPC_URLS = {
mainnet: 'https://fullnode.mainnet.sui.io:443',
testnet: 'https://fullnode.testnet.sui.io:443',
} as const;
const dAppKit = createDAppKit({
networks: ['mainnet', 'testnet'],
defaultNetwork: 'mainnet',
createClient: (network) => new SuiGrpcClient({ network, baseUrl: GRPC_URLS[network] }),
});
// Switch to a different network
dAppKit.switchNetwork('testnet');Parameters
network-TNetworks[number]- The network to switch to. Must be one of the networks configured when creating the dApp Kit instance.
Return Value
Returns void. The action completes synchronously and updates the network state immediately.