useChain
A hook that returns the current chain as well as a function to set the chain.
Note: when calling setChain
the chain that's passed in must be defined in
your initial createConfig
call.
Import
import { useChain } from "@account-kit/react";
Usage
import { useChain } from "@account-kit/react";
// Assuming the chain sepolia is defined in your initial createConfig call
import { sepolia } from "@account-kit/infra";
function ComponentUsingChain() {
const { chain, setChain, isSettingChain } = useChain();
return (
<div>
<p>Current Chain: {chain.id}</p>
<button
onClick={() => setChain({ chain: sepolia })}
disabled={isSettingChain}
>
Set Chain
</button>
</div>
);
}
Parameters
mutationArgs
UseChainParams
optional properties which contain mutation arg overrides
Returns
UseChainResult
an object containing the current chain and a function to set the chain as well as loading state of setting the chain