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.

Example

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
,
});

Param

Configuration parameters for creating a Modular Account V2.

Call Signature

1function createModularAccountV2<TTransport, TSigner>(
2 config,
3): Promise<ModularAccountV2<TSigner>>;

Defined in: account-kit/smart-contracts/src/ma-v2/account/modularAccountV2.ts:86

Type Parameters

Type ParameterDefault type

TTransport extends Transport

Transport

TSigner extends SmartAccountSigner<any>

SmartAccountSigner<any>

Parameters

ParameterType

config

CreateModularAccountV2Params<TTransport, TSigner>

Returns

Promise<ModularAccountV2<TSigner>>

Call Signature

1function createModularAccountV2<TTransport>(
2 config,
3): Promise<WebauthnModularAccountV2>;

Defined in: account-kit/smart-contracts/src/ma-v2/account/modularAccountV2.ts:93

Type Parameters

Type ParameterDefault type

TTransport extends Transport

Transport

Parameters

ParameterType

config

CreateWebauthnModularAccountV2Params<TTransport>

Returns

Promise<WebauthnModularAccountV2>