Optional
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: UseBatchSessionProps
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 ( <ErrorGuard errors={[error, waitError]}> <Button title="Use Session to Mint Twice" onClickFunc={txTwice} isLoading={isPending || waitIsLoading} /> </ErrorGuard> );}; Copy
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 ( <ErrorGuard errors={[error, waitError]}> <Button title="Use Session to Mint Twice" onClickFunc={txTwice} isLoading={isPending || waitIsLoading} /> </ErrorGuard> );};
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: UseBatchSessionProps
Example