useRegisterPasskey
Hook for registering a new passkey wallet
Import
import { useRegisterPasskey } from '@zerodev/wallet-react'Usage
import { useRegisterPasskey } from '@zerodev/wallet-react'
import { useAccount } from 'wagmi'
function Register() {
const registerPasskey = useRegisterPasskey()
const { address, isConnected } = useAccount()
if (isConnected) {
return <p>Wallet created: {address}</p>
}
return (
<button
onClick={() => registerPasskey.mutateAsync()}
disabled={registerPasskey.isPending}
>
{registerPasskey.isPending ? 'Registering...' : 'Create Wallet'}
</button>
)
}Parameters
This hook takes no mutation variables. It triggers the browser's WebAuthn prompt to create a new passkey.
Return Types
mutate
() => void
The mutation function to register a passkey. Triggers the WebAuthn browser prompt.
mutateAsync
() => Promise<void>
Similar to mutate but returns a promise. Resolves when the passkey is registered 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).