useSwitchChain
Hook for switching chain
Import
import { useSwitchChain } from '@zerodev/waas'Usage
import { useSwitchChain, useChains } from '@zerodev/waas'
function App() {
const { switchChain } = useSwitchChain()
const chains = useChains()
return (
<button onClick={() => switchChain({ chainId: chains[0].id })}>
Switch Chain
</button>
)
}Parameters
import { type UseSwitchChainParameters } from '@zerodev/waas';Return Types
import { type UseSwitchChainReturnType } from '@zerodev/waas'switchChain
(variables: SwitchChainVariables) => void
The mutation function to swich chain.
-
variables
-
chainId
numberID of chain to switch to.
-
switchChainAsync
(variables: SwitchChainVariables) => Promise<SwitchChainData>
Similar to switchChain but returns a promise.
-
variables
-
chainId
numberID of chain to switch to.
-
data
SwitchChainData | undefined
error
Error | null
The error object for the mutation, if an error was encountered.
isError / isIdle / isPending / isSuccess
boolean
Boolean variables derived from status.
isPaused
boolean
- will be
trueif the mutation has beenpaused. - see Network Mode for more information.
status
'idle' | 'pending' | 'error' | 'success'
'idle'initial status prior to the mutation function executing.'pending'if the mutation is currently executing.'error'if the last mutation attempt resulted in an error.'success'if the last mutation attempt was successful.
reset
() => void
A function to clean the mutation internal state (e.g. it resets the mutation to its initial state).