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

import { 
function createModularAccountV2<TTransport extends Transport = Transport, TSigner extends SmartAccountSigner = SmartAccountSigner<any>>(config: CreateModularAccountV2Params<TTransport, TSigner>): Promise<ModularAccountV2<TSigner>>
createModularAccountV2
} from "@account-kit/smart-contracts";
import {
class LocalAccountSigner<T extends HDAccount | PrivateKeyAccount | LocalAccount>

Represents a local account signer and provides methods to sign messages and transactions, as well as static methods to create the signer from mnemonic or private key.

LocalAccountSigner
} from "@aa-sdk/core";
import {
function alchemy(config: AlchemyTransportConfig): AlchemyTransport

Creates an Alchemy transport with the specified configuration options. When sending all traffic to Alchemy, you must pass in one of rpcUrl, apiKey, or jwt. If you want to send Bundler and Paymaster traffic to Alchemy and Node traffic to a different RPC, you must pass in alchemyConnection and nodeRpcUrl.

alchemy
,
const sepolia: Chain
sepolia
} from "@account-kit/infra";
const
const MNEMONIC: "..."
MNEMONIC
= "...";
const
const RPC_URL: "..."
RPC_URL
= "...";
const
const signer: LocalAccountSigner<{ address: Address; nonceManager?: NonceManager | undefined; sign: (parameters: { hash: Hash; }) => Promise<Hex>; ... 7 more ...; getHdKey: () => HDKey; }>
signer
=
class LocalAccountSigner<T extends HDAccount | PrivateKeyAccount | LocalAccount>

Represents a local account signer and provides methods to sign messages and transactions, as well as static methods to create the signer from mnemonic or private key.

LocalAccountSigner
.
LocalAccountSigner<T extends HDAccount | PrivateKeyAccount | LocalAccount>.mnemonicToAccountSigner(key: string, opts?: HDOptions): LocalAccountSigner<HDAccount>

Creates a LocalAccountSigner using the provided mnemonic key and optional HD options.

mnemonicToAccountSigner
(
const MNEMONIC: "..."
MNEMONIC
);
const
const chain: Chain
chain
=
const sepolia: Chain
sepolia
;
const
const transport: AlchemyTransport
transport
=
function alchemy(config: AlchemyTransportConfig): AlchemyTransport

Creates an Alchemy transport with the specified configuration options. When sending all traffic to Alchemy, you must pass in one of rpcUrl, apiKey, or jwt. If you want to send Bundler and Paymaster traffic to Alchemy and Node traffic to a different RPC, you must pass in alchemyConnection and nodeRpcUrl.

alchemy
({
rpcUrl: string
rpcUrl
:
const RPC_URL: "..."
RPC_URL
});
const
const modularAccountV2: ModularAccountV2<LocalAccountSigner<{ address: Address; nonceManager?: NonceManager | undefined; sign: (parameters: { hash: Hash; }) => Promise<Hex>; ... 7 more ...; getHdKey: () => HDKey; }>>
modularAccountV2
= await
createModularAccountV2<AlchemyTransport, LocalAccountSigner<{ address: Address; nonceManager?: NonceManager | undefined; sign: (parameters: { hash: Hash; }) => Promise<Hex>; ... 7 more ...; getHdKey: () => HDKey; }>>(config: CreateModularAccountV2Params<...>): Promise<...>
createModularAccountV2
({
mode?: "default" | undefined
mode
: "default", // or "7702"
chain: Chain
chain
,
signer: LocalAccountSigner<{ address: Address; nonceManager?: NonceManager | undefined; sign: (parameters: { hash: Hash; }) => Promise<Hex>; ... 7 more ...; getHdKey: () => HDKey; }>
signer
,
transport: AlchemyTransport
transport
,
});

Parameters

config

CreateModularAccountV2Params | CreateWebauthnModularAccountV2Params Configuration parameters for creating a Modular Account V2.

Returns

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