Skip to content

useCreateSession

Hook for creating session for kernel v3 account

Import

import { useCreateSession } from '@zerodev/waas'

Usage

import { useCreateSession } from '@zerodev/waas';
import { toGasPolicy } from '@zerodev/permissions/policies';
 
function App() {
  const { write } = useCreateSession();
  
  return (
    <button onClick={() => {
      write({
        policies: [toGasPolicy({ allowed: 1000000000n })]
      })
    }}>
      Create Session
    </button>
  )
}

Parameters

No parameter needed.

Return Types

import { type UseCreateSessionReturnType } from '@zerodev/waas'


TanStack Query mutation docs

write

(variables: CreateSessionVariables) => void

The mutation function to create session for v3 kernel account.

  • variables

    • policies
      Policy[] The policies of the session.

writeAsync

(variables: CreateSessionVariables) => Promise<CreateSessionData>

Similar to write but returns a promise.

  • variables

    • policies
      Policy[] The policies of the session.

data

CreateSessionData | undefined

  • sessionKey
    0x${string} The private key of the session.
  • sessionId
    0x${string} The id of the session.
  • smartAccount
    0x${string} The address of smart account.
  • enableSignature
    0x${string} The signature to enable session.
  • policies
    Policy[] The policies of session.

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 true if the mutation has been paused.
  • 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).