Alchemy Logo

buildUserOperationFromTxs

function buildUserOperationFromTxs<
  TTransport,
  TChain,
  TAccount,
  TEntryPointVersion,
  TContext,
>(
  client_,
  args,
): Promise<BuildUserOperationFromTransactionsResult<TEntryPointVersion>>;

Defined in: aa-sdk/core/src/actions/smartAccount/buildUserOperationFromTxs.ts:74

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 type { RpcTransactionRequest } from "viem";
import { smartAccountClient } from "./smartAccountClient";
 
const requests: RpcTransactionRequest[] = [
  {
    from, // ignored
    to,
    data: encodeFunctionData({
      abi: ContractABI.abi,
      functionName: "func",
      args: [arg1, arg2, ...],
    }),
  },
  {
    from, // ignored
    to,
    data: encodeFunctionData({
      abi: ContractABI.abi,
      functionName: "func",
      args: [arg1, arg2, ...],
    }),
  },
];
const uoStruct = await smartAccountClient.buildUserOperationFromTxs({
  requests,
});
 
// signUserOperation signs the above unsigned user operation struct built
// using the account connected to the smart account client
const request = await smartAccountClient.signUserOperation({ uoStruct });
 
// You can use the BundlerAction `sendRawUserOperation` (packages/core/src/actions/bundler/sendRawUserOperation.ts)
// to send the signed user operation request to the bundler, requesting the bundler to send the signed uo to the
// EntryPoint contract pointed at by the entryPoint address parameter
const entryPointAddress = client.account.getEntryPoint().address;
const uoHash = await smartAccountClient.sendRawUserOperation({
  request,
  entryPoint: entryPointAddress,
});

Type ParameterDefault type

TTransport extends Transport

Transport

TChain extends undefined | Chain

undefined | Chain

TAccount extends any

any

TEntryPointVersion extends GetEntryPointFromAccount<TAccount>

GetEntryPointFromAccount<TAccount>

TContext extends any

any

ParameterTypeDescription

client_

Client<TTransport, TChain, TAccount>

the smart account client to use to make RPC calls

args

BuildTransactionParameters<TAccount, TContext, TEntryPointVersion>

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

Promise<BuildUserOperationFromTransactionsResult<TEntryPointVersion>>

a Promise containing the built user operation

Was this page helpful?