# buildUserOperationFromTx | @aa-sdk/core

> Overview of the buildUserOperationFromTx function from @aa-sdk/core

> For the complete documentation index, see [llms.txt](/docs/llms.txt).

{/* This file is auto-generated by TypeDoc. Do not edit manually. */}

```ts
function buildUserOperationFromTx<
  TChain,
  TAccount,
  TChainOverride,
  TContext,
  TEntryPointVersion,
>(
  client_,
  args,
  overrides?,
  context?,
): Promise<UserOperationStruct<TEntryPointVersion>>;
```

Defined in: [aa-sdk/core/src/actions/smartAccount/buildUserOperationFromTx.ts:62](https://github.com/alchemyplatform/aa-sdk/blob/main/aa-sdk/core/src/actions/smartAccount/buildUserOperationFromTx.ts#L62)

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

```ts
import type { RpcTransactionRequest } from "viem";
import { smartAccountClient } from "./smartAccountClient";
// [!code focus:99]
// buildUserOperationFromTx converts a traditional Ethereum transaction and returns
// the unsigned user operation struct after constructing the user operation struct
// through the middleware pipeline
const tx: RpcTransactionRequest = {
  from, // ignored
  to,
  data: encodeFunctionData({
    abi: ContractABI.abi,
    functionName: "func",
    args: [arg1, arg2, ...],
  }),
};
const uoStruct = await smartAccountClient.buildUserOperationFromTx(tx);

// 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 Parameters

<table>
  <thead>
    <tr>
      <th align="left">Type Parameter</th>
      <th align="left">Default type</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        `TChain` *extends* `undefined` | [`Chain`](https://viem.sh)
      </td>

      <td>
        `undefined` | [`Chain`](https://viem.sh)
      </td>
    </tr>

    <tr>
      <td>
        `TAccount` *extends*
        | `undefined`
        | [`SmartContractAccount`](../type-aliases/SmartContractAccount)
      </td>

      <td>
        | `undefined`
        | [`SmartContractAccount`](../type-aliases/SmartContractAccount)
      </td>
    </tr>

    <tr>
      <td>
        `TChainOverride` *extends* `undefined` | [`Chain`](https://viem.sh)
      </td>

      <td>
        `undefined` | [`Chain`](https://viem.sh)
      </td>
    </tr>

    <tr>
      <td>
        `TContext` *extends*
        | `undefined`
        | [`UserOperationContext`](../type-aliases/UserOperationContext)
      </td>

      <td>
        | `undefined`
        | [`UserOperationContext`](../type-aliases/UserOperationContext)
      </td>
    </tr>

    <tr>
      <td>
        `TEntryPointVersion` *extends* keyof [`EntryPointRegistryBase`](../interfaces/EntryPointRegistryBase)\<`unknown`>
      </td>

      <td>
        [`GetEntryPointFromAccount`](../type-aliases/GetEntryPointFromAccount)\<`TAccount`>
      </td>
    </tr>

  </tbody>
</table>

## Parameters

<table>
  <thead>
    <tr>
      <th align="left">Parameter</th>
      <th align="left">Type</th>
      <th align="left">Description</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        `client_`
      </td>

      <td>
        [`Client`](https://viem.sh)\<[`Transport`](https://viem.sh), `TChain`, `TAccount`>
      </td>

      <td>
        the smart account client to use for RPC requests
      </td>
    </tr>

    <tr>
      <td>
        `args`
      </td>

      <td>
        [`SendTransactionParameters`](https://viem.sh)\<`TChain`, `TAccount`, `TChainOverride`>
      </td>

      <td>
        the send tx parameters
      </td>
    </tr>

    <tr>
      <td>
        `overrides?`
      </td>

      <td>
        [`UserOperationOverrides`](../type-aliases/UserOperationOverrides)\<`TEntryPointVersion`>
      </td>

      <td>
        optional overrides to use for any of the fields
      </td>
    </tr>

    <tr>
      <td>
        `context?`
      </td>

      <td>
        `TContext`
      </td>

      <td>
        if the smart account client requires additinoal context for building UOs
      </td>
    </tr>

  </tbody>
</table>

## Returns

`Promise`\<[`UserOperationStruct`](../type-aliases/UserOperationStruct)\<`TEntryPointVersion`>>

a Promise containing the built user operation