Skip to content
Alchemy Logo

useDropAndReplaceUserOperation

function useDropAndReplaceUserOperation<TEntryPointVersion, TAccount>(
  config,
): UseDropAndReplaceUserOperationResult<TEntryPointVersion, TAccount>;

Defined in: account-kit/react/src/hooks/useDropAndReplaceUserOperation.ts:110

Custom hook that handles the drop and replace user operation for a given client and mutation arguments.

import React from "react";
import {
  useDropAndReplaceUserOperation,
  useSendUserOperation,
  useSmartAccountClient,
} from "@account-kit/react";
 
export function ComponentWithDropAndReplaceUO() {
  const { client } = useSmartAccountClient({});
 
  const { sendUserOperationAsync, isSendingUserOperation } =
    useSendUserOperation({
      client,
    });
  const { dropAndReplaceUserOperation, isDroppingAndReplacingUserOperation } =
    useDropAndReplaceUserOperation({
      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={async () => {
          const { request } = await sendUserOperationAsync({
            uo: {
              target: "0xTARGET_ADDRESS",
              data: "0x",
              value: 0n,
            },
          });
 
          dropAndReplaceUserOperation({
            uoToDrop: request,
          });
        }}
        disabled={isSendingUserOperation || isDroppingAndReplacingUserOperation}
      >
        {isSendingUserOperation
          ? "Sending..."
          : isDroppingAndReplacingUserOperation
            ? "Replacing..."
            : "Send then Replace UO"}
      </button>
    </div>
  );
}

Type ParameterDefault type

TEntryPointVersion extends keyof EntryPointRegistryBase<unknown>

TAccount extends SupportedAccounts

SupportedAccounts

ParameterTypeDescription

config

UseDropAndReplaceUserOperationArgs<TEntryPointVersion, TAccount>

The configuration parameters including the client and other mutation arguments. ref

UseDropAndReplaceUserOperationResult<TEntryPointVersion, TAccount>

The result containing the mutation function, result data, loading state, and any error. ref

Was this page helpful?