useSwitchChain
Hook to change the current network of the wallet.
Usage
import { useSwitchChain } from "@starknet-react/core";
import { constants } from "starknet";
const { switchChain, error } = useSwitchChain({
params: {
chainId: constants.StarknetChainId.SN_SEPOLIA,
},
});
Arguments
params
- Type:
SwitchStarknetChainParameters
Chain id on which to change. This type is defined in the Starknet Types package.
Returns
switchChain
- Type:
(args?: SwitchStarknetChainParameters) => void
Function to send the request to the user, optionally overriding the arguments to the hook.
switchChainAsync
- Type:
(args?: SwitchStarknetChainParameters) => Promise<boolean>
Send the request to the user and block until it receives a response.
data
- Type:
boolean | undefined
The resolved data. This type is defined in the Starknet Types package.
error
- Type:
Error | null
Any error thrown by the mutation.
reset
- Type:
() => void
Reset the mutation status.
variables
- Type:
TypedData | undefined
The variables passed to switchChain
or switchChainAsync
.
status
- Type:
"error" | "idle" | "pending" | "success"
The mutation status.
idle
: the mutation has not been triggered yet.pending
: the mutation is being executed, e.g. waiting for the user to confirm in their wallet.success
: the mutation executed without an error.error
: the mutation threw an error.
isError
- Type:
boolean
Derived from status
.
isIdle
- Type:
boolean
Derived from status
.
isPending
- Type:
boolean
Derived from status
.
isSuccess
- Type:
boolean
Derived from status
.