Skip to main content

Networks

Privy makes it easy to get and switch the network of a user's embedded wallet. You can find the full list of Privy's supported networks here.

info

Privy is proud to support apps building on Base! Just upgrade @privy-io/react-auth to version 1.32.0 or above, and switch your wallets to Base mainnet/testnet via the Chain IDs below.

Getting the current network

To get the embedded wallet's current network, simply find the embedded wallet's ConnectedWallet object from the useWallets array, and inspect its chainId property:

// Find the embedded wallet
const {wallets} = useWallets();
const embeddedWallet = wallets.find((wallet) => (wallet.walletClientType === 'privy'));
// Inspect its chainId
const chainId = embeddedWallet.chainId;
console.log(chainId);
// 'eip155:1' (as an example for Ethereum mainnet)

This will be a CAIP-2 formatted chain ID.

Switching networks

tip

If you need the user's wallet to always be on a given network, we recommend calling switchChain for the user's wallet on page load.

To switch the network of the user's embedded wallet, first find the embedded wallet's ConnectedWallet object from the useWallets array:

const const {wallets} = useWallets();
const embeddedWallet = wallets.find((wallet) => (wallet.walletClientType === 'privy'));

Then, call the object's switchChain method, passing your desired chain ID as a number or as a 0x-prefixed hexadecimal string:

// These lines are equivalent
await embeddedWallet.switchChain(137);
await embeddedWallet.switchChain('0x89');

switchChain returns a Promise that resolves to void once the wallet has successfully been switched to the target network. The Promise will reject with an error if the target chain is not supported.

This network switch will occur completely behind the scenes. You may choose to attach your own UIs to indicate the user's embedded wallet is switching networks.

info

If you're using an external library like ethers or viem, you should switch the wallet's network to your desired network before initializing the wallet's client/provider instance for that library (e.g. getEthersProvider for ethers and createWalletClient for viem).

If you switch a wallet's network after initializing the external library's wallet provider, the provider may have an outdated chain ID.

Supported networks

By default, embedded wallets can be used on the networks listed below.

tip

You can easily add additional networks to your app per these instructions!

NetworkChain IDSupported?
Arbitrum42161
Arbitrum Goerli421613
Avalanche C-Chain43114
Avalanche Fuji43113
Base8453
Base Goerli84531
Celo42220
Celo Alfajores44787
Ethereum1
Ethereum Goerli5
Ethereum Sepolia11155111
Linea59144
Linea Testnet59140
Optimism10
Optimism Goerli420
Polygon137
Polygon Mumbai80001

Adding additional networks

If your app doesn't use one of the default supported networks listed above, you can easily configure Privy to support your app's network! Simply follow the instructions below:

info

To support an additional network, first check if your desired network has a corresponding JSON representation in the @wagmi/chains library, a public repository of EVM networks. You can find the full list of networks supported by that library here.

If your network is included in @wagmi/chains, you can simply import the network and follow the instructions below.

If your network is not included in @wagmi/chains, you can instead build your own JSON representation of the network, that implements wagmi's Chain type. You can find the required fields of this type here.

First, install the latest version of the @privy-io/react-auth and @wagmi/chains SDKs:

npm i @privy-io/react-auth@latest @wagmi/chains

In particular, your @privy-io/react-auth dependency must be on version 1.37.0 or later.

Next, import your desired network(s) from @wagmi/chains:

As an example, here we import the @wagmi/chains objects for the Aurora mainnet and testnet:

// Replace this with any of the networks listed at https://wagmi.sh/core/chains#supported-chains
import {aurora, auroraTestnet} from '@wagmi/chains';

Lastly, configure your PrivyProvider with these additional network(s):

The config property of the PrivyProvider contains an optional additionalChains field. In this field, pass an array containing your imported chain objects from @wagmi/chains, like below:

<PrivyProvider
appId='your-privy-app-id'
config={{
...theRestOfYourConfig,
// Replace the entries in this array with the chains you imported from `@wagmi/chains`
additionalChains: [aurora, auroraTestnet]
}}
>
{/* your app's content */}
</PrivyProvider>

That's it! Your user's wallet can now take on-chain actions on any of Privy's default supported chains, or any other chains you've supplied in additionalChains.