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

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

Usage

1import React from "react";
2import {
3 useSendUserOperation,
4 useSmartAccountClient,
5} from "@account-kit/react";
6
7function ComponentWithSendUserOperation() {
8 const { client } = useSmartAccountClient({});
9
10 const { sendUserOperation, isSendingUserOperation } = useSendUserOperation({
11 client,
12 // optional parameter that will wait for the transaction to be mined before returning
13 waitForTxn: true,
14 onSuccess: ({ hash, request }) => {
15 // [optional] Do something with the hash and request
16 },
17 onError: (error) => {
18 // [optional] Do something with the error
19 },
20 // [optional] ...additional mutationArgs
21 });
22
23 return (
24 <div>
25 <button
26 onClick={() =>
27 sendUserOperation({
28 uo: {
29 target: "0xTARGET_ADDRESS",
30 data: "0x",
31 value: 0n,
32 },
33 })
34 }
35 disabled={isSendingUserOperation}
36 >
37 {isSendingUserOperation ? "Sending..." : "Send UO"}
38 </button>
39 </div>
40 );
41}

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