useCreateBasicSession
Hook for creating session for kernel v2 account
Import
import { useCreateBasicSession } from '@zerodev/waas'Usage
import { useCreateBasicSession, useKernelClient } from '@zerodev/waas';
import { ParamOperator } from '@zerodev/session-keys';
import { parseAbi } from 'viem';
function App() {
const { write } = useCreateBasicSession();
const { address } = useKernelClient();
const abi = parseAbi(['function mint(address _to) public']);
return (
<button onClick={() => {
write({
permissions: [
{
target: '0x34bE7f35132E97915633BC1fc020364EA5134863',
valueLimit: 0n,
abi: abi,
functionName: "mint",
args: [
{
operator: ParamOperator.EQUAL,
value: address,
},
],
}
]
})
}}>
Create Session
</button>
)
}Parameters
No parameter needed.
Return Types
import { type UseCreateBasicSessionReturnType } from '@zerodev/waas'write
(variables: CreateBasicSessionVariables) => void
The mutation function to create session for v2 kernel account.
-
variables
-
permissions
Permission<Abi>[]The permissions of the session.
-
writeAsync
(variables: CreateBasicSessionVariables) => Promise<CreateBasicSessionData>
Similar to write but returns a promise.
-
variables
-
permissions
Permission<Abi>[]The permissions of the session.
-
data
CreateBasicSessionData | 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. -
permissions
Permission<Abi>[]The permissions of the 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
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).