createModularAccountV2

Creates a ModularAccount V2 account, with the mode depending on the provided “mode” field. Possible modes include: “default”, which is SMA Bytecode, and “7702”, which is SMA 7702. Handles nonce generation, transaction encoding, and mode variant-specific behavior like initcode construction.

Import

1import { createModularAccountV2 } from "@account-kit/smart-contracts";

Usage

1import { createModularAccountV2 } from "@account-kit/smart-contracts";
2import { LocalAccountSigner } from "@aa-sdk/core";
3import { alchemy, sepolia } from "@account-kit/infra";
4
5const MNEMONIC = "...";
6const RPC_URL = "...";
7
8const signer = LocalAccountSigner.mnemonicToAccountSigner(MNEMONIC);
9
10const chain = sepolia;
11
12const transport = alchemy({ rpcUrl: RPC_URL });
13
14const modularAccountV2 = await createModularAccountV2({
15 mode: "default", // or "7702"
16 chain,
17 signer,
18 transport,
19});

Parameters

config

CreateModularAccountV2Params Configuration parameters for creating a Modular Account V2.

Returns

Promise<ModularAccountV2> A promise that resolves to an ModularAccountV2 providing methods for nonce retrieval, transaction execution, and more.