Skip to content

useChainId ​

Primitive for getting current chain ID.

Import ​

ts
import { useChainId } from '@wagmi/solid'

Usage ​

tsx
import { useChainId } from '@wagmi/solid'

function App() {
  const chainId = useChainId()
  
  return <p>Chain ID: {chainId()}</p>
}
ts
import { createConfig, http } from '@wagmi/solid'
import { mainnet, sepolia } from '@wagmi/solid/chains'

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

Parameters ​

ts
import { useChainId } from '@wagmi/solid'

useChainId.Parameters
useChainId.SolidParameters

Parameters are passed as a getter function to maintain Solid reactivity.

ts
useChainId(() => ({
  config,
}))

config ​

Config | undefined

Config to use instead of retrieving from the nearest WagmiProvider.

Return Type ​

ts
import { useChainId } from '@wagmi/solid'

useChainId.ReturnType

Accessor<number>

Returns an accessor containing the current chain ID from the config state.

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.

Action ​

Released under the MIT License.