Skip to content

getChainId

Action for getting current chain ID.

Import

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

Usage

ts
import { getChainId } from '@wagmi/core'
import { config } from './config'

const chainId = getChainId(config)
import { getChainId } from '@wagmi/core'
import { config } from './config'

const chainId = getChainId(config)
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(),
  },
})
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(),
  },
})

Return Type

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

number

Current chain ID from config.state.chainId.

Released under the MIT License.