Skip to content
Alchemy Logo

Light Account • Getting started

Getting started with Light Account is straightforward. Below you'll create a LightAccount (and the multi-owner variant) from @alchemy/smart-accounts and use them with viem's bundler client.

Most projects should use @alchemy/wallet-apis

@alchemy/wallet-apis defaults to Modular Account V2, but it can provision a Light Account too — pass creationHint: { accountType: "la-v2" } to requestAccount. createSmartWalletClient then bundles account creation, gas estimation, and the bundler client behind a single call. See the Wallet APIs quickstart. This page covers the lower-level path: instantiating LightAccount directly from @alchemy/smart-accounts and pairing it with viem's bundler client. Use it when you need fine-grained control over the wiring.

Prerequisites

  • minimum Typescript version of 5

Installation

npm i @alchemy/smart-accounts @alchemy/aa-infra viem

import { createBundlerClient } from "viem/account-abstraction";
import { createClient } from "viem";
import { privateKeyToAccount, generatePrivateKey } from "viem/accounts";
import { sepolia } from "viem/chains";
import { alchemyTransport } from "@alchemy/common";
import { toLightAccount } from "@alchemy/smart-accounts";
import { estimateFeesPerGas } from "@alchemy/aa-infra";
 
const ALCHEMY_API_KEY = "your-api-key";
const transport = alchemyTransport({ apiKey: ALCHEMY_API_KEY });
const rpcClient = createClient({ chain: sepolia, transport });
 
const account = await toLightAccount({
  client: rpcClient,
  owner: privateKeyToAccount(generatePrivateKey()),
  version: "v2.0.0",
});
 
const bundlerClient = createBundlerClient({
  account,
  client: rpcClient,
  chain: sepolia,
  transport,
  userOperation: { estimateFeesPerGas },
});
 
const hash = await bundlerClient.sendUserOperation({
  calls: [{ to: "0x0000000000000000000000000000000000000000", value: 0n, data: "0x" }],
});
Address calculation

For LightAccount, the address is derived from the version, owner, and an optional salt (default 0n). Same inputs → same address. MultiOwnerLightAccount follows the same rule but takes an array of owners and is locked to v2.0.0 (no version param). Pass accountAddress to connect to an existing account whose contract-derived address doesn't match the signer.

Reference: EIP-4337 — first-time account creation.

Was this page helpful?