useVerifyOTP
Import
import { useVerifyOTP } from '@zerodev/wallet-react'Usage
import { useState } from 'react'
import { useVerifyOTP } from '@zerodev/wallet-react'
import { useAccount } from 'wagmi'
function VerifyCode({
otpId,
otpEncryptionTargetBundle,
}: {
otpId: string
otpEncryptionTargetBundle: string
}) {
const [code, setCode] = useState('')
const verifyOTP = useVerifyOTP()
const { address, isConnected } = useAccount()
if (isConnected) {
return <p>Authenticated: {address}</p>
}
return (
<div>
<input
type="text"
value={code}
onChange={(e) => setCode(e.target.value)}
placeholder="Enter verification code"
/>
<button
onClick={() =>
verifyOTP.mutateAsync({ code, otpId, otpEncryptionTargetBundle })
}
disabled={verifyOTP.isPending || !code}
>
{verifyOTP.isPending ? 'Verifying...' : 'Verify'}
</button>
{verifyOTP.isError && <p>Error: {verifyOTP.error.message}</p>}
</div>
)
}Mutation Parameters
code
string
Required. The verification code entered by the user.
otpId
string
Required. The OTP identifier returned by useSendOTP.
otpEncryptionTargetBundle
string
Required. The encrypted OTP target bundle returned by useSendOTP. Pass it verbatim to the verify step.
connector
Connector | undefined
Optional Wagmi connector to verify the OTP with. If omitted, the hook uses the configured ZeroDev connector.
Return Types
mutate
(variables: { code: string; otpId: string; otpEncryptionTargetBundle: string; connector?: Connector }) => void
The mutation function to verify the OTP.
mutateAsync
(variables: { code: string; otpId: string; otpEncryptionTargetBundle: string; connector?: Connector }) => Promise<void>
Similar to mutate but returns a promise. Resolves when the code is verified and the wallet is connected.
data
void
This mutation does not return data. On success, the Wagmi connector is connected and the account is available via useAccount.
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).