Skip to content

How to set up a smart account client

Once users are authenticated, you can start landing transactions onchain using a Smart Account Client. Setting up a new account client is easy using the useSmartAccountClient hook!

This extends viem's Client, enabling account creation, sending transactions, signing messages, sponsoring gas, and more. It's also EIP-1193 compliant, so you can swap it in for other web3 providers like window.ethereum.

Usage

The following sets up a Smart Account Client that will allow you to create a new smart account and send transactions signed by your Alchemy Signer.

import { useSmartAccountClient } from "@account-kit/react";
 
const { client, address, isLoadingClient } = useSmartAccountClient({});

The default smart account type is Modular Account V2 — the most cost-effective and advanced smart account option. You can specify other account types with additional configuration.

Note: React hooks only support Alchemy Signer. If you want to use a 3rd party signer, see this guide.

Configuration Options

You can customize your client by specifying additional parameters to change account type, add gas sponsorship, etc. These parameters are optional.

Account Type

We recommend using ModularAccountV2 as it is the cheapest and most advanced Smart Account, but you can specify other smart contract account types as needed. Learn more about the different smart accounts here.

  • type (string) - Defines the smart account type. Options:
    • "ModularAccountV2" (recommended and default)
    • "LightAccount"
    • "MultiOwnerLightAccount"
    • "MultiOwnerModularAccount"

Looking for 7702 support? Learn how to use advanced ModularAccountV2 functionality here.

Gas Sponsorship

To improve transaction UX, we recommend sponsoring gas for users.

See the full guide for gas sponsorship.

Advanced options

Options
UsageParameterType
Smart contract account implementationtypeOne of "ModularAccountV2", "LightAccount", "MultiOwnerLightAccount", "MultiOwnerModularAccount"
Sponsor gas for users. Get your policy ID herepolicyIdstring
Simulate user operations before sending (i.e. use alchemyUserOperationSimulator)useSimulationboolean
Custom middleware to run before requesting sponsorshipcustomMiddlewareClientMiddlewareFn
Override fee estimation middleware (if you are using our RPCs, it's important to use the default alchemyFeeEstimator)feeEstimatorClientMiddlewareFn
Override gas estimation middleware (the default middleware calls the underlying bundler RPC to eth_estimateUserOperationGas)gasEstimatorClientMiddlewareFn
Override middleware that signs user operation(s)signUserOperationClientMiddlewareFn
Advanced account paramsaccountParamsAccountConfig with the following fields:
  • mode: "default" | "7702"
  • entryPoint: EntryPointDef
  • signerEntity: SignerEntity
  • salt: bigint
  • factoryAddress: Address
  • initCode: Hex
  • accountAddress: Address