Skip to content

useSendUserOperation

A hook that returns functions for sending user operations. You can also optionally wait for a user operation to be mined and get the transaction hash before returning using waitForTx. Like any method that takes a smart account client, throws an error if client undefined or is signer not authenticated.

Import

import { useSendUserOperation } from "@account-kit/react";

Usage

import {
  useSendUserOperation,
  useSmartAccountClient,
} from "@account-kit/react";
 
function ComponentWithSendUserOperation() {
  const { client } = useSmartAccountClient({
    type: "MultiOwnerModularAccount",
  });
  const { sendUserOperation, isSendingUserOperation } = useSendUserOperation({
    client,
    // optional parameter that will wait for the transaction to be mined before returning
    waitForTxn: true,
    onSuccess: ({ hash, request }) => {
      // [optional] Do something with the hash and request
    },
    onError: (error) => {
      // [optional] Do something with the error
    },
    // [optional] ...additional mutationArgs
  });
 
  return (
    <div>
      <button
        onClick={() =>
          sendUserOperation({
            uo: {
              target: "0xTARGET_ADDRESS",
              data: "0x",
              value: 0n,
            },
          })
        }
        disabled={isSendingUserOperation}
      >
        {isSendingUserOperation ? "Sending..." : "Send UO"}
      </button>
    </div>
  );
}

Parameters

params

UseSendUserOperationArgs<TEntryPointVersion, TAccount> the parameters for the hook including the client, a flag to wait for tx mining, and mutation args. ref

Returns

UseSendUserOperationResult<TEntryPointVersion, TAccount> functions and state for sending UOs. ref