Modular Account • Getting started

It is easy to get started with Modular Account! We will show you two different ways using Alchemy Infra or 3rd party infra.

Install packages

Prerequisites

Installation

First, install the @account-kit/smart-contracts package.

$yarn add @account-kit/smart-contracts
>yarn add @account-kit/infra

With Alchemy Infra

Then you can do the following:

1import { createModularAccountAlchemyClient } from "@account-kit/smart-contracts";
2import { sepolia, alchemy } from "@account-kit/infra";
3import { LocalAccountSigner } from "@aa-sdk/core";
4import { generatePrivateKey } from "viem/accounts";
5
6const alchemyAccountClient = await createModularAccountAlchemyClient({
7 transport: alchemy({ apiKey: "your-api-key" }),
8 chain: sepolia,
9 signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey()),
10});
Address calculation

For Modular Account, the address of the smart account will be calculated as a combination of the owners and the salt. You will get the same smart account address each time you supply the same owners, the signer(s) used to create the account for the first time. You can also optionally supply salt if you want a different address for the same owners param (the default salt is 0n).

If you want to use a signer to connect to an account whose address does not map to the contract-generated address, you can supply the accountAddress to connect with the account of interest. In that case, the signer address is not used for address calculation, but only for signing the operation.

With 3rd-party infra

If you’re using a 3rd-party for infra, we also expose a client that you can use to interact with Modular Account using other RPC providers.

1import { createMultiOwnerModularAccountClient } from "@account-kit/smart-contracts";
2import { LocalAccountSigner } from "@aa-sdk/core";
3import { sepolia } from "viem/chains";
4import { http } from "viem";
5import { generatePrivateKey } from "viem/accounts";
6
7const accountClient = await createMultiOwnerModularAccountClient({
8 chain: sepolia,
9 transport: http("RPC_URL"),
10 signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey()),
11});

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.