Function useSendSponsoredTransaction

  • Parameters

    • Optional mutationProps: {
          gcTime?: number;
          meta?: Record<string, unknown>;
          networkMode?: NetworkMode;
          onError?: ((error, variables, context) => unknown);
          onMutate?: ((variables) => any);
          onSettled?: ((data, error, variables, context) => unknown);
          onSuccess?: ((data, variables, context) => unknown);
          retry?: RetryValue<any>;
          retryDelay?: RetryDelayValue<any>;
          scope?: MutationScope;
          throwOnError?: boolean | ((error) => boolean);
      }
      • Optional gcTime?: number
      • Optional meta?: Record<string, unknown>
      • Optional networkMode?: NetworkMode
      • Optional onError?: ((error, variables, context) => unknown)
          • (error, variables, context): unknown
          • Parameters

            • error: any
            • variables: any
            • context: any

            Returns unknown

      • Optional onMutate?: ((variables) => any)
          • (variables): any
          • Parameters

            • variables: any

            Returns any

      • Optional onSettled?: ((data, error, variables, context) => unknown)
          • (data, error, variables, context): unknown
          • Parameters

            • data: any
            • error: any
            • variables: any
            • context: any

            Returns unknown

      • Optional onSuccess?: ((data, variables, context) => unknown)
          • (data, variables, context): unknown
          • Parameters

            • data: any
            • variables: any
            • context: any

            Returns unknown

      • Optional retry?: RetryValue<any>
      • Optional retryDelay?: RetryDelayValue<any>
      • Optional scope?: MutationScope
      • Optional throwOnError?: boolean | ((error) => boolean)

    Returns UseMutationResult<UserOpResponse, any, UseSendSponsoredTransactionProps, any>

    Description

    Sends a transaction, using a paymaster for sponsorship.

    Mutation function args: UseSendSponsoredTransactionProps

    Example


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

    export const SendSponsoredTx = () => {

    const { smartAccountAddress } = useSmartAccount();

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

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

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


    const mintNftTx = () => mutate({
    transactions: {
    to: "0x1758f42Af7026fBbB559Dc60EcE0De3ef81f665e",
    data: encodeFunctionData({
    abi: parseAbi(["function safeMint(address _to)"]),
    functionName: "safeMint",
    args: [smartAccountAddress],
    }),
    }
    });

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