Skip to content
Alchemy Logo

useSendUserOperation

function useSendUserOperation<TEntryPointVersion, TAccount>(
  params,
): UseSendUserOperationResult<TEntryPointVersion, TAccount>;

Defined in: account-kit/react/src/hooks/useSendUserOperation.ts:131

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 React from "react";
import {
  useSendUserOperation,
  useSmartAccountClient,
} from "@account-kit/react";
 
function ComponentWithSendUserOperation() {
  const { client } = useSmartAccountClient({});
 
  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>
  );
}

Type ParameterDefault type

TEntryPointVersion extends keyof EntryPointRegistryBase<unknown>

TAccount extends SupportedAccounts

SupportedAccounts

ParameterTypeDescription

params

UseSendUserOperationArgs<TEntryPointVersion, TAccount>

the parameters for the hook including the client, a flag to wait for tx mining, and mutation args. ref

UseSendUserOperationResult<TEntryPointVersion, TAccount>

functions and state for sending UOs. ref

Was this page helpful?