# Handling Chain

The following guide will show you how to handle networks with Openfort's smart wallets using the EIP-1193 provider.

:::info
You can also use Viem's [`switchChain`](https://wagmi.sh/core/api/actions/switchChain) method with the chain ID you wish to switch to.
:::

## Get the current chain

To get the current network, you can use the `eth_chainId` request (with no `params`)

:::code-group

```ts [getCurrentNetwork.ts]
import openfort from "./openfortConfig"
// This example assumes you have already checked that Openfort 'embeddedState' is 
// `ready` and the user is `authenticated`
const provider = await openfort.embeddedWallet.getEthereumProvider();

const chainId = await provider.request({
  method: "eth_chainId",
  params: [],
});
```

```ts [openfortConfig.ts]
import { Openfort } from '@openfort/openfort-js';

const openfort = new Openfort({
  baseConfiguration: {
    publishableKey: "YOUR_OPENFORT_PUBLISHABLE_KEY",
  },
  shieldConfiguration: {
    shieldPublishableKey: "YOUR_SHIELD_PUBLISHABLE_KEY",
  },
});

export default openfort;
```

:::

## Switch chains

To switch the smart wallet to a different network, send a [`wallet_switchEthereumChain`](https://docs.metamask.io/wallet/reference/wallet_switchethereumchain/) **JSON-RPC request to the wallet's EIP-1193 provider**. In the request's `params`, specify your target `chainId` as a hexadecimal string.

:::code-group

```ts [switchNetwork.ts]
import openfort from "./openfortConfig"
// This example assumes you have already checked that Openfort 'embeddedState' is 
// `ready` and the user is `authenticated`
const provider = await openfort.embeddedWallet.getEthereumProvider();

await provider.request({
  method: 'wallet_switchEthereumChain',
  // Replace '0xaa36a7' (Sepolia) with the chainId of your target network
  params: [{chainId: '0xaa36a7'}],
});
```

```ts [openfortConfig.ts]
import { Openfort } from '@openfort/openfort-js';

const openfort = new Openfort({
  baseConfiguration: {
    publishableKey: "YOUR_OPENFORT_PUBLISHABLE_KEY",
  },
  shieldConfiguration: {
    shieldPublishableKey: "YOUR_SHIELD_PUBLISHABLE_KEY",
  },
});

export default openfort;
```

:::
