useChainId

Hook for accessing and setting the current chain ID.
1import { useChainId } from '@avalabs/avacloud-waas-react';
2
3function ChainSelector() {
4 const { chainId, setChainId } = useChainId();
5
6 return (
7 <div>
8 <p>Current Chain ID: {chainId}</p>
9 <button onClick={() => setChainId(43114)}>
10 Switch to Mainnet
11 </button>
12 </div>
13 );
14}

Returns

  • chainId : number - Current chain ID
  • setChainId : (chainId: number) => void - Function to update the chain ID

For any additional questions, please view our other knowledge base articles or contact a support team member via the chat button. Examples are for illustrative purposes only.

Learn More About AvaCloud | Download Case Studies | Schedule an AvaCloud Demo