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.EVM chain switching is available on web SDK version 31.0.0+ and React Native SDKs version 32.0.0+.
Setup
To enable EVM chain switching, you need to configure multiple networks when initializing the Magic SDK: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.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.JavaScript
Switching Chains
Use theswitchChain
method to switch between configured EVM networks:
JavaScript
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