import type { MutationOptionsWithoutMutationFn } from "../hooks"; import { type BuildUserOpOptions, type Transaction } from "../utils"; import { getChain, type GetSessionParams } from "@biconomy/account"; import type { Hex } from "viem"; export type UseBatchSessionProps = { /** The BuildUserOpOptions options. See https://bcnmy.github.io/biconomy-client-sdk/types/BuildUserOpOptions.html for further detail */ options?: BuildUserOpOptions; /** The transactions to be batched. */ transactions: Transaction | Transaction[]; correspondingIndexes?: GetSessionParams["leafIndex"]; /** The smart account address to be used for the session. */ smartAccountAddress?: Hex; }; export type PostUseBatchSessionProps = UseBatchSessionProps & { chain: ReturnType; bundlerUrl: string; biconomyPaymasterApiKey: string; }; /** @description Uses a previously created batch session (see: https://bcnmy.github.io/useAA/functions/useCreateBatchSession.html) which batches transactions in the context of a users smart account. Mutation function args: {@link UseBatchSessionProps} @example ```tsx import { useBatchSession, useUserOpWait, Options } from "@biconomy/useAA" import { polygonAmoy } from "viem/chains" import { encodeFunctionData, parseAbi } from "wagmi" export const UseBatchSession = ({ smartAccountAddress }) => { const { mutate, data: userOpResponse, error, isPending, } = useBatchSession(); const { isLoading: waitIsLoading, isSuccess: waitIsSuccess, error: waitError, data: waitData, } = useUserOpWait(userOpResponse); const nftMintTx: Transaction = { to: "0x1758f42Af7026fBbB559Dc60EcE0De3ef81f665e", data: encodeFunctionData({ abi: parseAbi(["function safeMint(address _to)"]), functionName: "safeMint", args: [smartAccountAddress], }), }; const txTwice = () => mutate({ transactions: [nftMintTx, nftMintTx], correspondingIndexes: [0, 1], options: Options.Sponsored, smartAccountAddress }); useEffect(() => { if (waitData?.success === "true") { console.log(waitData?.receipt?.transactionHash); } }, [waitData]); return (