buildUserOperationFromTx

1function buildUserOperationFromTx<
2 TChain,
3 TAccount,
4 TChainOverride,
5 TContext,
6 TEntryPointVersion,
7>(
8 client_,
9 args,
10 overrides?,
11 context?,
12): Promise<UserOperationStruct<TEntryPointVersion>>;

Defined in: aa-sdk/core/src/actions/smartAccount/buildUserOperationFromTx.ts:62

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

Example

1import type { RpcTransactionRequest } from "viem";
2import { smartAccountClient } from "./smartAccountClient";
3// [!code focus:99]
4// buildUserOperationFromTx converts a traditional Ethereum transaction and returns
5// the unsigned user operation struct after constructing the user operation struct
6// through the middleware pipeline
7const tx: RpcTransactionRequest = {
8 from, // ignored
9 to,
10 data: encodeFunctionData({
11 abi: ContractABI.abi,
12 functionName: "func",
13 args: [arg1, arg2, ...],
14 }),
15};
16const uoStruct = await smartAccountClient.buildUserOperationFromTx(tx);
17
18// signUserOperation signs the above unsigned user operation struct built
19// using the account connected to the smart account client
20const request = await smartAccountClient.signUserOperation({ uoStruct });
21
22// You can use the BundlerAction `sendRawUserOperation` (packages/core/src/actions/bundler/sendRawUserOperation.ts)
23// to send the signed user operation request to the bundler, requesting the bundler to send the signed uo to the
24// EntryPoint contract pointed at by the entryPoint address parameter
25const entryPointAddress = client.account.getEntryPoint().address;
26const uoHash = await smartAccountClient.sendRawUserOperation({ request, entryPoint: entryPointAddress });

Type Parameters

Type ParameterDefault type

TChain extends undefined | Chain

undefined | Chain

TAccount extends | undefined | SmartContractAccount

| undefined | SmartContractAccount

TChainOverride extends undefined | Chain

undefined | Chain

TContext extends | undefined | UserOperationContext

| undefined | UserOperationContext

TEntryPointVersion extends keyof EntryPointRegistryBase<unknown>

GetEntryPointFromAccount<TAccount>

Parameters

ParameterTypeDescription

client_

Client<Transport, TChain, TAccount>

the smart account client to use for RPC requests

args

SendTransactionParameters<TChain, TAccount, TChainOverride>

the send tx parameters

overrides?

UserOperationOverrides<TEntryPointVersion>

optional overrides to use for any of the fields

context?

TContext

if the smart account client requires additinoal context for building UOs

Returns

Promise<UserOperationStruct<TEntryPointVersion>>

a Promise containing the built user operation