Skip to content
Alchemy Logo

3rd party smart contracts

You aren't limited to the accounts defined in @alchemy/smart-accounts. If you'd like to bring your own smart account, you have two options:

  1. Use any library that returns a viem-compatible SmartAccount — those plug into the same createBundlerClient flow we use for Light Account and Modular Account V2.
  2. Build your own SmartAccount implementation with viem's toSmartAccount primitive.

Any object that satisfies viem's SmartAccount interface works:

import { createBundlerClient } from "viem/account-abstraction";
import { createClient } from "viem";
import { sepolia } from "viem/chains";
import { alchemyTransport } from "@alchemy/common";
import { estimateFeesPerGas } from "@alchemy/aa-infra";
import { myAccount } from "./my-account"; // your custom SmartAccount
 
const transport = alchemyTransport({ apiKey: "your-api-key" });
const rpcClient = createClient({ chain: sepolia, transport });
 
const bundlerClient = createBundlerClient({
  account: myAccount,
  client: rpcClient,
  chain: sepolia,
  transport,
  userOperation: { estimateFeesPerGas },
});
 
const hash = await bundlerClient.sendUserOperation({
  calls: [{ to: "0x0000000000000000000000000000000000000000", value: 0n, data: "0x" }],
});

Use toSmartAccount from viem/account-abstraction. You provide:

  • The entry point version your account uses (0.6, 0.7, or 0.8).
  • getAddress() — counterfactual or deployed address.
  • getFactoryArgs() — factory address + calldata (for first-time deploys).
  • encodeCalls() — encode one or more calls into your account's execution calldata.
  • signUserOperation() / signMessage / signTypedData — signing methods bound to your account's owner.

The viem docs walk through a full custom example. Once you have a SmartAccount, pass it to createBundlerClient exactly like the snippet above.

Built an SDK or guide that defines a custom SmartAccount for Wallet APIs? Open a PR to add it here.

@alchemy/smart-accounts ships viem-compatible implementations of Light Account, Modular Account V1, and Modular Account V2, plus the validation/permission builders for MAv2. If your use case fits one of those, you'll save a lot of custom-account boilerplate.

If you want to keep Alchemy's smart account implementations while using non-Alchemy infrastructure, see the low-level infrastructure guides:

Was this page helpful?