# toModularAccountV2

> Overview of the toModularAccountV2 function

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

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

```ts
function toModularAccountV2<TMode>(param0): Promise<ModularAccountV2>;
```

Defined in: [packages/smart-accounts/src/ma-v2/accounts/account.ts:108](https://github.com/alchemyplatform/aa-sdk/blob/v5.x.x/packages/smart-accounts/src/ma-v2/accounts/account.ts#L108)

Creates a MAv2 account.

## Example

```ts
import { createPublicClient } from "viem";
import {
  createBundlerClient,
  createPaymasterClient,
} from "viem/account-abstraction";
import { sepolia } from "viem/chains";
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
import { alchemyTransport } from "@alchemy/common";
import { estimateFeesPerGas } from "@alchemy/aa-infra";
import { toModularAccountV2 } from "@alchemy/smart-accounts";

const transport = alchemyTransport({ apiKey: "YOUR_API_KEY" });

// 1. Create a MAv2 smart account
const account = await toModularAccountV2({
  client: createPublicClient({ chain: sepolia, transport }),
  owner: privateKeyToAccount(generatePrivateKey()),
});

// 2. Create a bundler client with the account
const bundlerClient = createBundlerClient({
  account,
  chain: sepolia,
  transport,
  userOperation: {
    estimateFeesPerGas,
  },
  // Optional: sponsor gas with a paymaster
  paymaster: createPaymasterClient({ transport }),
  paymasterContext: { policyId: "YOUR_POLICY_ID" },
});

// 3. Send a user operation
const hash = await bundlerClient.sendUserOperation({
  calls: [{ to: "0x...", value: 0n, data: "0x" }],
});

const receipt = await bundlerClient.waitForUserOperationReceipt({ hash });
```

## Type Parameters

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

  <tbody>
    <tr>
      <td>
        `TMode` *extends* `Mode`
      </td>

      <td>
        `Mode`
      </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>
        `param0`
      </td>

      <td>
        [`ToModularAccountV2Params`](../type-aliases/ToModularAccountV2Params)\<`TMode`>
      </td>

      <td>
        The parameters for creating a MAv2 account.
      </td>
    </tr>

  </tbody>
</table>

## Returns

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

A MAv2 account.