buildUserOperationFromTxs

Performs buildUserOperationFromTx in batch and builds into a single, yet to be signed UserOperation (UO) struct. The output user operation struct will be filled with all gas fields (and paymaster data if a paymaster is used) based on the transactions data (to, data, value, maxFeePerGas, maxPriorityFeePerGas) computed using the configured ClientMiddlewares on the SmartAccountClient.

Import

1import { buildUserOperationFromTxs } from "@aa-sdk/core";

Usage

1import type { RpcTransactionRequest } from "viem";
2import { smartAccountClient } from "./smartAccountClient";
3
4const requests: RpcTransactionRequest[] = [
5{
6from, // ignored
7to,
8data: encodeFunctionData({
9 abi: ContractABI.abi,
10 functionName: "func",
11 args: [arg1, arg2, ...],
12}),
13},
14{
15from, // ignored
16to,
17data: encodeFunctionData({
18 abi: ContractABI.abi,
19 functionName: "func",
20 args: [arg1, arg2, ...],
21}),
22},
23];
24const uoStruct = await smartAccountClient.buildUserOperationFromTxs({
25requests,
26});
27
28// signUserOperation signs the above unsigned user operation struct built
29// using the account connected to the smart account client
30const request = await smartAccountClient.signUserOperation({ uoStruct });
31
32// You can use the BundlerAction `sendRawUserOperation` (packages/core/src/actions/bundler/sendRawUserOperation.ts)
33// to send the signed user operation request to the bundler, requesting the bundler to send the signed uo to the
34// EntryPoint contract pointed at by the entryPoint address parameter
35const entryPointAddress = client.account.getEntryPoint().address;
36const uoHash = await smartAccountClient.sendRawUserOperation({
37request,
38entryPoint: entryPointAddress,
39});

Parameters

client_

Client<TTransport, TChain, TAccount> the smart account client to use to make RPC calls

args

BuildTransactionParameters an object containing the requests to build as well as, the account if not hoisted, the context, the overrides, and optionally a flag to enable signing of the UO via the underlying middleware

Returns

Promise<BuildUserOperationFromTransactionsResult<TEntryPointVersion>> a Promise containing the built user operation