useChainId

Hook for accessing the chain ID of the network the current wallet is connected to

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

Example

import { useChainId } from "@thirdweb-dev/react";
const App = () => {
const chainId = useChainId();
return <div>{chainId}</div>;
};
function useChainId(): number | undefined;

Returns

let returnType: number | undefined;

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

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