Skip to content

useUserOpWait

Description

This function will wait for the userOp to be mined and return the receipt

Usage

import {
  useSendTransaction,
  useUserOpWait,
  useSmartAccount,
} from "@biconomy/use-aa";
import { polygonAmoy } from "viem/chains";
import { encodeFunctionData, parseAbi, Hex } from "viem";
import React, { useEffect } from "react"
 
export const SendTx = () => {
  const { smartAccountAddress } = useSmartAccount();
 
  const {
    mutate,
    data: userOpResponse,
    error,
    isPending,
  } = useSendTransaction();
 
  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 (
    <button
      title={isPending || waitIsLoading ? "Loading..." : "Use Session to Mint Twice"}
      onClick={mintNftTx}
    />
  );
};

Parameters

type UserOpResponse = {
  userOpHash: string;
  wait(_confirmations?: number): Promise<UserOpReceipt>;
  waitForTxHash(): Promise<UserOpStatus>;
};

Returns

UserOpReceipt

Source

hooks/useUserOpWait.ts:76