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 before returning.

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,
    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

Returns

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