Network
Use these standard EIP-1193 / EIP-3326 / EIP-3085 methods to read the currently connected chain, switch the user to a different one, or register a custom EVM network with StarKey.
| Network | Chain ID (hex) | Chain ID (decimal) |
|---|---|---|
| Ethereum | 0x1 | 1 |
| Base | 0x2105 | 8453 |
| Polygon | 0x89 | 137 |
| Monad Testnet | 0x279f | 10143 |
eth_chainId
Returns the currently connected chain, as a hex string.
const chainId: string = await provider.request({ method: 'eth_chainId' })
// '0x1'The provider also exposes this synchronously as provider.chainId once connected, without a request round-trip.
wallet_switchEthereumChain
Prompts the user to switch to a different, already-known chain.
try {
await provider.request({
method: 'wallet_switchEthereumChain',
params: [{ chainId: '0x2105' }], // Base
})
} catch (error: any) {
if (error.code === 4902) {
// chain not yet added to StarKey — call wallet_addEthereumChain first
}
}Params: [{ chainId: string }] — hex-encoded chain ID to switch to.
Returns: Promise<null> on success. Throws with code: 4902 if the chain hasn’t been added to StarKey yet — fall back to wallet_addEthereumChain in that case.
wallet_addEthereumChain
Registers a new EVM network with StarKey (and switches to it), for chains the wallet doesn’t already know about.
await provider.request({
method: 'wallet_addEthereumChain',
params: [
{
chainId: '0x279f', // Monad Testnet
chainName: 'Monad Testnet',
nativeCurrency: { name: 'Monad', symbol: 'MON', decimals: 18 },
rpcUrls: ['https://testnet-rpc.monad.xyz'],
blockExplorerUrls: ['https://testnet.monadexplorer.com'],
},
],
})Params: [AddEthereumChainParameter] — see EIP-3085 for the full field list (chainId, chainName, nativeCurrency, rpcUrls, blockExplorerUrls, iconUrls).
Returns: Promise<null> on success — StarKey switches to the new chain immediately after adding it.
Error handling
wallet_switchEthereumChainrejects withcode: 4902for an unrecognized chain — add it first withwallet_addEthereumChain, then retry the switch.- Both methods reject with
code: 4001if the user declines the prompt.
Notes
- Listen for the
chainChangedevent to react when the user switches networks from the StarKey UI directly, rather than only through your dApp’s own switch call. - Re-read
eth_accountsafter a network change — StarKey may present a different active account per chain.
Best practices
- Read
eth_chainIdright after connecting to confirm the dApp and wallet agree on the active chain before building a transaction. - Try
wallet_switchEthereumChainfirst and only fall back towallet_addEthereumChainon a4902error, rather than always adding the chain.