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.
Prerequisites
- minimum Typescript version of 5
Installation
npm i @account-kit/smart-contractsThe code snippets below demonstrate how to use LightAccount and MultiOwnerLightAccount with Smart Wallets. They create the account and send a UserOperation from it.
import { createLightAccountAlchemyClient } from "@account-kit/smart-contracts";
import { sepolia, alchemy } from "@account-kit/infra";
import { LocalAccountSigner } from "@aa-sdk/core";
import { generatePrivateKey } from "viem";
const lightAccountClient = await createLightAccountAlchemyClient({
transport: alchemy({ apiKey: "your-api-key" })
chain: sepolia,
signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey()),
});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