# 切换网络

您可以通过<kbd>wallet\_switchEthereumChain</kbd> 和 <kbd>wallet\_addEthereumChain</kbd> 切换到指定的<kbd>chainId</kbd> 链上

```javascript
try {
  await NaboxWallet.request({
    method: 'wallet_switchEthereumChain',
    params: [{ chainId: '0x1' }], // 16进制chainId
  });
} catch (error) {
  if (error.code === 4902) { // 当前链不支持
    try {
      await NaboxWallet.request({
        method: 'wallet_addEthereumChain',
        params: [
          {
            chainId: '0x38',
            chainName: '...',
            rpcUrls: ['https://...']
          },
        ],
      });
    } catch (error) {
      consolle.log(error)
    }
  }
}
```
