Skip to content

addChain

Action for adding an EVM chain to the wallet.

Import

ts
import { addChain } from '@wagmi/core'

Usage

ts
import { avalanche } from 'viem/chains'
import { addChain } from '@wagmi/core'
import { config } from './config'

await addChain(config, { chain: avalanche })
ts
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'

export const config = createConfig({
  chains: [mainnet, sepolia],
  transports: {
    [mainnet.id]: http(),
    [sepolia.id]: http(),
  },
})

Parameters

ts
import { type AddChainParameters } from '@wagmi/core'

connector

Connector | undefined

Connector to add chain with.

ts
import { avalanche } from 'viem/chains'
import { getAccount, addChain } from '@wagmi/core'
import { config } from './config'

const { connector } = getAccount(config)
const result = await addChain(config, {
  connector, 
  chain: avalanche
})
ts
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'

export const config = createConfig({
  chains: [mainnet, sepolia],
  transports: {
    [mainnet.id]: http(),
    [sepolia.id]: http(),
  },
})

Error

ts
import { type AddChainErrorType } from '@wagmi/core'

TanStack Query

ts
import {
  type AddChainData,
  type AddChainVariables,
  type AddChainMutate,
  type AddChainMutateAsync,
  addChainMutationOptions,
} from '@wagmi/core/query'

Viem

Released under the MIT License.