Skip to main content

useChainId() function

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

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

Example

You can get the chain ID of the connected wallet by using the hook as follows:

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

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

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

Signature:

export declare function useChainId(): number | undefined;

Returns:

number | undefined