> ## Documentation Index
> Fetch the complete documentation index at: https://docs.magic.link/llms.txt
> Use this file to discover all available pages before exploring further.

# EVM Chain Switching

> Switch between different EVM-compatible blockchain networks seamlessly with Magic's EVM chain switching feature.

## Overview

Magic's EVM chain switching feature allows users to seamlessly switch between different EVM-compatible blockchain networks without requiring separate wallet instances. This feature supports Ethereum, Polygon, Base, Arbitrum, Optimism, and custom EVM networks.

<Note>
  EVM chain switching is available on web SDK version 31.0.0+ and React Native SDKs version 32.0.0+.
</Note>

## Setup

To enable EVM chain switching, you need to configure multiple networks when initializing the Magic SDK:

<Warning>
  **Legacy Network Parameter**: When using the EVM Extension, you no longer need to pass the `network` parameter to the Magic constructor. The old approach `new Magic('API_KEY', { network: 'sepolia' })` is not required with the EVM Extension.
</Warning>

<Note>
  **Built-in Networks**: Ethereum mainnet (chainId: 1) and Sepolia testnet (chainId: 11155111) are included out of the box and don't need to be configured. You can switch to them using `magic.evm.switchEVMChain(1)` or `magic.evm.switchEVMChain(11155111)` regardless of your extension configuration.
</Note>

```javascript JavaScript icon="square-js" theme={null}
import { Magic } from 'magic-sdk';
import { EVMExtension } from '@magic-ext/evm';

const customPolygonOptions = {
  rpcUrl: 'https://polygon-rpc.com/', // Polygon RPC URL
  chainId: 137, // Polygon chain id
  default: true, // Set as default network
};

const customOptimismOptions = {
  rpcUrl: 'https://mainnet.optimism.io',
  chainId: 10,
};

const magic = new Magic('YOUR_API_KEY', {
  extensions: [
    new EVMExtension([customPolygonOptions, customOptimismOptions]),
  ],
});
```

## Switching Chains

Use the `switchChain` method to switch between configured EVM networks:

```javascript JavaScript icon="square-js" theme={null}
// Switch to Ethereum mainnet (chainId: 1)
await magic.evm.switchChain(1);

// Switch to Sepolia testnet (chainId: 11155111)
await magic.evm.switchChain(11155111);

// Switch to Optimism network (chainId: 10)
await magic.evm.switchChain(10);

// Verify the network switch
const provider = new ethers.BrowserProvider(magic.rpcProvider);
const network = await provider.getNetwork();
console.log(network.chainId); // => 1, 11155111, or 10
```

## Network Configuration Options

When configuring EVM networks, you can specify the following options:

| Parameter | Type    | Description                                |
| --------- | ------- | ------------------------------------------ |
| `rpcUrl`  | String  | RPC URL for the blockchain network         |
| `chainId` | Number  | Chain ID for the network                   |
| `default` | Boolean | Set this network as the default (optional) |

## Complete Example

Here's a complete example showing how to set up and use EVM chain switching:

```javascript JavaScript icon="square-js" theme={null}
import { Magic } from 'magic-sdk';
import { EVMExtension } from '@magic-ext/evm';
import { ethers } from 'ethers';

const magic = new Magic('YOUR_API_KEY', {
  extensions: [
    new EVMExtension([
      {
        rpcUrl: 'https://polygon-rpc.com/',
        chainId: 137,
        default: true,
      },
      {
        rpcUrl: 'https://mainnet.optimism.io',
        chainId: 10,
      },
    ]),
  ],
});

// Switch EVM network
await magic.evm.switchChain(10);

// Verify the network switch
const provider = new ethers.BrowserProvider(magic.rpcProvider);
const network = await provider.getNetwork();
console.log(network.chainId); // => 10
```

## Resources

* [JavaScript SDK Reference](/embedded-wallets/sdk/client-side/javascript#evm-module)
* [React Native SDK Reference](/embedded-wallets/sdk/client-side/react-native#evm-module)
* [Blockchains](/embedded-wallets/blockchains/overview)
