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): AlchemyTransportCreates 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: Chainsepolia } 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: Chainchain = const sepolia: Chainsepolia;
const const transport: AlchemyTransporttransport = function alchemy(config: AlchemyTransportConfig): AlchemyTransportCreates 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: stringrpcUrl: 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" | undefinedmode: "default", // or "7702"
chain: Chainchain,
signer: LocalAccountSigner<{
address: Address;
nonceManager?: NonceManager | undefined;
sign: (parameters: {
hash: Hash;
}) => Promise<Hex>;
... 7 more ...;
getHdKey: () => HDKey;
}>signer,
transport: AlchemyTransporttransport,
});
Param
Configuration parameters for creating a Modular Account V2.
Call Signature
Defined in: account-kit/smart-contracts/src/ma-v2/account/modularAccountV2.ts:86
Type Parameters
Parameters
Returns
Promise
<ModularAccountV2
<TSigner
>>
Call Signature
Defined in: account-kit/smart-contracts/src/ma-v2/account/modularAccountV2.ts:93
Type Parameters
Parameters
Returns
Promise
<WebauthnModularAccountV2
>