Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

wallet_switchEthereumChain

Switch to a different chain.

Authentication Required: Yes

Request

await jaw.provider.request({
  method: 'wallet_switchEthereumChain',
  params: [{ chainId: '0x89' }],
});

Parameters

NameTypeRequiredDescription
chainId0x${string}YesTarget chain ID in hexadecimal format

Example

[{ "chainId": "0x89" }]

Response

Returns null on success.

Type: null

Behavior

  • Switches to the specified chain if supported
  • Emits chainChanged event with the new chain ID
  • All subsequent transactions use the new chain
  • Only supported chains can be switched to

Errors

CodeDescription
4001User rejected the request
4100Unauthorized (not authenticated)
4902Chain not supported

Example

Basic Chain Switch

try {
  await jaw.provider.request({
    method: 'wallet_switchEthereumChain',
    params: [{ chainId: '0x89' }], // Polygon
  });
 
  console.log('Switched to Polygon');
} catch (error) {
  if (error.code === 4902) {
    console.error('Polygon is not supported');
  }
}

Switch with Event Listener

// Listen for chain changes
jaw.provider.on('chainChanged', (chainId) => {
  console.log('Chain changed to:', parseInt(chainId, 16));
});
 
// Switch chain
await jaw.provider.request({
  method: 'wallet_switchEthereumChain',
  params: [{ chainId: '0x2105' }], // Base
});

Related Methods