Optional
Creates a session to be used when submitting tx in the context of a users smart account.
Mutation function args: UseCreateSessionWithDistributedKeyProps
import { useCreateSessionWithDistributedKey, useUserOpWait, Options } from "@biconomy/useAA"import { polygonAmoy } from "viem/chains"import { encodeFunctionData, parseAbi } from "wagmi"export const CreateSessionWithDistributedKey = ({userSmartAccountAddress}) => { const policy = [ { contractAddress: "0x1758f42Af7026fBbB559Dc60EcE0De3ef81f665e", functionSelector: "safeMint(address)", rules: [ { offset: 0, condition: 0, referenceValue: userSmartAccountAddress, }, ], interval: { validUntil: 0, validAfter: 0, }, valueLimit: 0n, }, ]; const { mutate, data: userOpResponse, error, isPending, } = useCreateSessionWithDistributedKey(); const { isLoading: waitIsLoading, isSuccess: waitIsSuccess, error: waitError, data: waitData, } = useUserOpWait(userOpResponse); useEffect(() => { if (waitData?.success === "true") { console.log(waitData?.receipt?.transactionHash); } }, [waitData]); const createSessionWithDistributedKeyHandler = () => mutate({ policy, options: Options.Sponsored, }); return ( <ErrorGuard errors={[error, waitError]}> <Button title="Create a session" onClickFunc={createSessionWithDistributedKeyHandler} isLoading={isPending || waitIsLoading} /> </ErrorGuard> );}; Copy
import { useCreateSessionWithDistributedKey, useUserOpWait, Options } from "@biconomy/useAA"import { polygonAmoy } from "viem/chains"import { encodeFunctionData, parseAbi } from "wagmi"export const CreateSessionWithDistributedKey = ({userSmartAccountAddress}) => { const policy = [ { contractAddress: "0x1758f42Af7026fBbB559Dc60EcE0De3ef81f665e", functionSelector: "safeMint(address)", rules: [ { offset: 0, condition: 0, referenceValue: userSmartAccountAddress, }, ], interval: { validUntil: 0, validAfter: 0, }, valueLimit: 0n, }, ]; const { mutate, data: userOpResponse, error, isPending, } = useCreateSessionWithDistributedKey(); const { isLoading: waitIsLoading, isSuccess: waitIsSuccess, error: waitError, data: waitData, } = useUserOpWait(userOpResponse); useEffect(() => { if (waitData?.success === "true") { console.log(waitData?.receipt?.transactionHash); } }, [waitData]); const createSessionWithDistributedKeyHandler = () => mutate({ policy, options: Options.Sponsored, }); return ( <ErrorGuard errors={[error, waitError]}> <Button title="Create a session" onClickFunc={createSessionWithDistributedKeyHandler} isLoading={isPending || waitIsLoading} /> </ErrorGuard> );};
Description
Creates a session to be used when submitting tx in the context of a users smart account.
Mutation function args: UseCreateSessionWithDistributedKeyProps
Example