Function useCreateBatchSession

  • Parameters

    Returns UseMutationResult<UserOpResponse, Error, UseCreateBatchSessionProps>

    Description

    Creates a sessions to be used when submitting batches of txs simultaneously in the context of a users smart account.

    Mutation function args: UseCreateBatchSessionProps

    Example


    import { useCreateBatchSession, useUserOpWait, Options } from "@biconomy/useAA"
    import { polygonAmoy } from "viem/chains"
    import { encodeFunctionData, parseAbi } from "wagmi"

    export const CreateBatchSession = ({userSmartAccountAddress}) => {

    const leafPolicy: Policy = {
    interval: {
    validUntil: 0,
    validAfter: 0,
    },
    contractAddress: "0x1758f42Af7026fBbB559Dc60EcE0De3ef81f665e",
    functionSelector: "safeMint(address)",
    rules: [
    {
    offset: 0,
    condition: 0,
    referenceValue: userSmartAccountAddress,
    },
    ],
    valueLimit: 0n,
    }

    const policyLeaves: Policy[] = [leafPolicy, leafPolicy];

    const {
    mutate,
    data: userOpResponse,
    error,
    isPending,
    } = useCreateBatchSession();

    const {
    isLoading: waitIsLoading,
    isSuccess: waitIsSuccess,
    error: waitError,
    data: waitData,
    } = useUserOpWait(userOpResponse);

    const grantPermission = () =>
    mutate({
    policy: policyLeaves,
    options: Options.Sponsored,
    });

    useEffect(() => {
    if (waitData?.success === "true") {
    console.log(waitData?.receipt?.transactionHash);
    }
    }, [waitData]);


    return (
    <ErrorGuard errors={[error, waitError]}>
    <Button
    title="Grant Permission"
    onClickFunc={grantPermission}
    isLoading={isPending || waitIsLoading}
    />
    </ErrorGuard>
    );
    };