Light Account • Getting started

It is easy to get started with Light Account! We will show you how to create and send user operations for both LightAccount and MultiOwnerLightAccount using @alchemy/aa-alchemy.

Install packages

Prerequisites

Installation

$npm i @account-kit/smart-contracts

Create a client and send a user operation

The code snippets below demonstrate how to use LightAccount and MultiOwnerLightAccount with Account Kit. They create the account and send a UserOperation from it.

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

For LightAccount, the address of the smart account will be calculated as a combination of the version, the owner, and the salt. You will get the same smart account address each time you supply the same version and owner. Alternatively, you can supply salt if you want a different address for the same version and owner params (the default salt is 0n). For MultiOwnerLightAccount, the same pattern follows, except that it takes an array of owner addresses instead of a single owner address.

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 used for signing the operation.

Reference: https://eips.ethereum.org/EIPS/eip-4337#first-time-account-creation