Networks
WaaP supports standard Sui networks. You can switch between them programmatically.
Supported Networks
The SDK supports the following standard Sui network identifiers:
sui:mainnetsui:testnetsui:devnetsui:localnet
Switching Networks
You can request to switch the wallet's active network using the sui:switchChain feature standard.
Switch Network (standard)
import { getWallets } from '@mysten/wallet-standard'
const wallets = getWallets().get()
const wallet = wallets.find(w => w.name === 'WaaP')
if (!wallet) return
try {
// Request the wallet to switch its active chain
await wallet.features['sui:switchChain'].switchChain({ chain: 'sui:testnet' })
} catch (error) {
console.error("Failed to switch network:", error)
}
Switch Network (with @mysten/dapp-kit)
When using @mysten/dapp-kit, you should coordinate the wallet switch with the dApp's network context.
import { useCurrentWallet, useSuiClientContext } from '@mysten/dapp-kit'
import { useState } from 'react'
export function NetworkSwitcher() {
const { currentWallet } = useCurrentWallet()
const ctx = useSuiClientContext()
const [isSwitching, setIsSwitching] = useState(false)
const switchToTestnet = async () => {
setIsSwitching(true)
try {
// 1. Request wallet to switch
await currentWallet.features['sui:switchChain'].switchChain({ chain: 'sui:testnet' })
// 2. Update dApp context
ctx.selectNetwork('testnet')
console.log('Switched to testnet')
} catch (e) {
console.error('Failed to switch:', e)
} finally {
setIsSwitching(false)
}
}
return (
<button onClick={switchToTestnet} disabled={isSwitching}>
Switch to Testnet
</button>
)
}
Configuring Networks
Configure Networks (standard)
If you are not using @mysten/dapp-kit, you can define your network configuration and use the SuiClient directly.
import { getFullnodeUrl, SuiClient } from '@mysten/sui/client'
// 1. Define your network configuration
const networks = {
mainnet: { url: getFullnodeUrl('mainnet') },
testnet: { url: getFullnodeUrl('testnet') },
devnet: { url: getFullnodeUrl('devnet') },
localnet: { url: 'http://127.0.0.1:9000' },
}
// 2. Create a client for your desired network
const client = new SuiClient({ url: networks.testnet.url })
Configure Networks (with @mysten/dapp-kit)
When using @mysten/dapp-kit, supported networks need to be defined. This configuration drives the useSuiClient and useSuiClientContext hooks.
import { createNetworkConfig, SuiClientProvider, WalletProvider } from '@mysten/dapp-kit'
import { getFullnodeUrl } from '@mysten/sui/client'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
// 1. Define your network configuration
const { networkConfig } = createNetworkConfig({
mainnet: { url: getFullnodeUrl('mainnet') },
testnet: { url: getFullnodeUrl('testnet') },
devnet: { url: getFullnodeUrl('devnet') },
localnet: { url: 'http://127.0.0.1:9000' },
})
const queryClient = new QueryClient()
export function Providers({ children }: { children: React.ReactNode }) {
return (
<QueryClientProvider client={queryClient}>
{/* 2. Configure SuiClientProvider with your networks */}
{/* defaultNetwork controls which network is active on load */}
<SuiClientProvider networks={networkConfig} defaultNetwork="testnet">
<WalletProvider>
{children}
</WalletProvider>
</SuiClientProvider>
</QueryClientProvider>
)
}