1.5 KiB
1.5 KiB
title, description
| title | description |
|---|---|
| useChainId | Hook for getting current chain ID. |
useChainId
Hook for getting current chain ID.
Import
import { useChainId } from 'wagmi'
Usage
::: code-group
import { useChainId } from 'wagmi'
function App() {
const chainId = useChainId()
}
<<< @/snippets/react/config.ts[config.ts] :::
Parameters
import { type UseChainIdParameters } from 'wagmi'
config
Config | undefined
Config to use instead of retrieving from the nearest WagmiProvider.
::: code-group
import { useChainId } from 'wagmi'
import { config } from './config' // [!code focus]
function App() {
const chainId = useChainId({
config, // [!code focus]
})
}
<<< @/snippets/react/config.ts[config.ts] :::
Return Type
import { type UseChainIdReturnType } from 'wagmi'
number
Current chain ID from config.state.chainId.
::: info
Only returns chain IDs for chains configured via createConfig's chains parameter.
If the active connection chainId is not from a chain included in your Wagmi Config, useChainId will return the last configured chain ID.
:::