useChainId ​
Composable for getting current chain ID.
Import ​
ts
import { useChainId } from '@wagmi/vue'
Usage ​
vue
<script setup lang="ts">
import { useChainId } from '@wagmi/vue'
const chainId = useChainId()
</script>
ts
import { http, createConfig } from '@wagmi/vue'
import { mainnet, sepolia } from '@wagmi/vue/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})
Parameters ​
ts
import { type UseChainIdParameters } from '@wagmi/vue'
config ​
Config | undefined
Config
to use instead of retrieving from the WagmiPlugin
.
vue
<script setup lang="ts">
import { useChainId } from '@wagmi/vue'
import { config } from './config'
const chainId = useChainId({
config,
})
</script>
ts
import { http, createConfig } from '@wagmi/vue'
import { mainnet, sepolia } from '@wagmi/vue/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})
Return Type ​
ts
import { type UseChainIdReturnType } from '@wagmi/vue'
number
Current chain ID from config.state.chainId
.