Network
Reading the network
network on useWallet is reactive — it updates whenever the user switches network from the StarKey UI.
import { useWallet } from '@aptos-labs/wallet-adapter-react'
const { network } = useWallet()Changing network
changeNetwork requests a network switch on the connected wallet. Not every wallet supports this — wrap the call in try/catch and fall back gracefully if it rejects.
import { Network } from '@aptos-labs/ts-sdk'
import { useWallet } from '@aptos-labs/wallet-adapter-react'
const { changeNetwork } = useWallet()
const onSwitchNetwork = async () => {
try {
await changeNetwork(Network.TESTNET)
} catch (error) {
// wallet doesn't support changeNetwork, or the user declined
}
}Related pages
Last updated on