Skip to content

Getting started with Modular Account

It is easy to get started with Modular Account! We will show you two different ways using @alchemy/aa-alchemy and @alchemy/aa-core.

With @alchemy/aa-alchemy

Install packages

npm
npm i @alchemy/aa-alchemy @alchemy/aa-core

Create a client

Then you can do the following:

connected-client.ts
import { createModularAccountAlchemyClient } from "@alchemy/aa-alchemy";
import { LocalAccountSigner, sepolia } from "@alchemy/aa-core";
 
export const chain = sepolia;
 
export const smartAccountClient = await createModularAccountAlchemyClient({
  apiKey: "YOUR_API_KEY",
  chain,
  // you can swap this out for any SmartAccountSigner
  signer: LocalAccountSigner.mnemonicToAccountSigner("OWNER_MNEMONIC"),
});

With @alchemy/aa-core

Install packages

If you are using @alchemy/aa-core, you will also want to add @alchemy/aa-accounts to get the Smart Account factory for Modular Account.

npm
npm i @alchemy/aa-core @alchemy/aa-accounts viem

Create a client

Then, you will need to create a SmartAccountClient

smartAccountClient.ts
import { createMultiOwnerModularAccount } from "@alchemy/aa-accounts";
import {
  LocalAccountSigner,
  SmartAccountSigner,
  createSmartAccountClient,
  polygonMumbai,
} from "@alchemy/aa-core";
import { http } from "viem";
 
const chain = polygonMumbai;
const signer: SmartAccountSigner = LocalAccountSigner.mnemonicToAccountSigner(
  "YOUR_OWNER_MNEMONIC"
);
const rpcTransport = http("https://polygon-mumbai.g.alchemy.com/v2/demo");
 
export const smartAccountClient = createSmartAccountClient({
  transport: rpcTransport,
  chain,
  account: await createMultiOwnerModularAccount({
    transport: rpcTransport,
    chain,
    signer,
  }),
});

Add decorators

The last step is optional but greatly improves the dev experience of interfacing with Modular Accounts. @alchemy/aa-accounts exports several Modular Account decorators that you can extend your client with.

Next, if you want to use a different signer with a smart account signer, check out choosing a signer. Otherwise, if you are ready to get on-chain, go to send user operations.