Skip to main content

useChainId

Hook for retrieving the chain ID of the network the user is connected to.

import { useChainId } from "@thirdweb-dev/react";

const chainId = useChainId();

Usage

import { useChainId } from "@thirdweb-dev/react";

function App() {
const chainId = useChainId();

return <div>{chainId}</div>;
}

Return value

Return Value

A number representing the current chain id, or undefined if the user is not connected to a wallet.

number | undefined;

For Example, if the user is connected to the Ethereum Mainnet, the return value will be 1.