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 Infra or 3rd party infra.

Install packages

Prerequisites Installation

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

yarn
yarn add @account-kit/smart-contracts
# if using alchemy infra
yarn add @account-kit/infra

With Alchemy Infra

Then you can do the following:

import { createModularAccountAlchemyClient } from "@account-kit/smart-contracts";
import { sepolia } from "@account-kit/infra";
import { LocalAccountSigner } from "@aa-sdk/core";
import { generatePrivateKey } from "viem/accounts";
 
const alchemyAccountClient = await createModularAccountAlchemyClient({
  apiKey: "your-api-key",
  chain: sepolia,
  signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey()),
});
## Errors were thrown in the sample, but not included in an error tag These errors were not marked as being expected: 2353. Expected: // @errors: 2353 Compiler Errors: index.ts [2353] 305 - Object literal may only specify known properties, and 'apiKey' does not exist in type 'AlchemyModularAccountClientConfig<LocalAccountSigner<{ address: `0x${string}`; nonceManager?: NonceManager | undefined; sign: (parameters: { hash: `0x${string}`; }) => Promise<`0x${string}`>; experimental_signAuthorization: (parameters: Authorization) => Promise<...>; ... 5 more ...; type: "local"; }>>'.

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.

import { createMultiOwnerModularAccountClient } from "@account-kit/smart-contracts";
import { LocalAccountSigner } from "@aa-sdk/core";
import { sepolia } from "viem/chains";
import { http } from "viem";
import { generatePrivateKey } from "viem/accounts";
 
const accountClient = await createMultiOwnerModularAccountClient({
  chain: sepolia,
  transport: http("RPC_URL"),
  signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey()),
});

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.