1.5 KiB
1.5 KiB
title, description
| title | description |
|---|---|
| useChainId | Composable for getting current chain ID. |
useChainId
Composable for getting current chain ID.
Import
import { useChainId } from '@wagmi/vue'
Usage
::: code-group
<script setup lang="ts">
import { useChainId } from '@wagmi/vue'
const chainId = useChainId()
</script>
<<< @/snippets/vue/config.ts[config.ts] :::
Parameters
import { type UseChainIdParameters } from '@wagmi/vue'
config
Config | undefined
Config to use instead of retrieving from the WagmiPlugin.
::: code-group
<script setup lang="ts">
import { useChainId } from '@wagmi/vue'
import { config } from './config' // [!code focus]
const chainId = useChainId({
config, // [!code focus]
})
</script>
<<< @/snippets/vue/config.ts[config.ts] :::
Return Type
import { type UseChainIdReturnType } from '@wagmi/vue'
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.
:::