Skip to content

useSmartAccountClient

The useSmartAccountClient hook is used to create a new AlchemySmartAccountClient attached to either a LightAccount or MultiOwnerModularAccount contract using the AlchemySigner.

Import

import { useSmartAccountClient } from "@alchemy/aa-alchemy/react";

Usage

useSmartAccountClient.tsx
import { useSmartAccountClient } from "@alchemy/aa-alchemy/react";
 
export function ComponentUsingClient() {
  // If this is the first time the hook is called, then the client will be undefined until the underlying account is connected to the client
  const { isLoadingClient, client } = useSmartAccountClient({
    type: "MultiOwnerModularAccount", // alternatively pass in "LightAccount",
    accountParams: {}, // optional param for overriding any account specific properties
  });
 
  if (isLoadingClient || !client) {
    return <div>Loading...</div>;
  }
 
  return (
    <div>
      <h1>Client is ready!</h1>
      <div>{client.account.address}</div>
    </div>
  );
}

Parameters

import { type UseSmartAccountClientProps } from "@alchemy/aa-alchemy/react";

type

"LightAccount" | "MultiOwnerModularAccount"

The underlying account type you want to use

accountParams

  | Omit<CreateLightAccountParams, "signer" | "transport" | "chain">
  | Omit<CreateMultiOwnerModularAccountParams, "signer" | "transport" | "chain">
  | undefined

An optional param object based on the type property passed in above. It allows for overriding the default account parameters.

CreateLightAccountParams
types.ts
export type CreateLightAccountParams<
  TTransport extends Transport = Transport,
  TSigner extends SmartAccountSigner = SmartAccountSigner,
  TLightAccountVersion extends GetLightAccountVersion<"LightAccount"> = GetLightAccountVersion<"LightAccount">,
  TEntryPointVersion extends GetEntryPointForLightAccountVersion<
    "LightAccount",
    TLightAccountVersion
  > = GetEntryPointForLightAccountVersion<"LightAccount", TLightAccountVersion>
> = Omit<
  CreateLightAccountBaseParams<
    TTransport,
    TSigner,
    "LightAccount",
    TLightAccountVersion,
    TEntryPointVersion
  >,
  "getAccountInitCode" | "entryPoint" | "version" | "abi" | "accountAddress"
> & {
  salt?: bigint;
  initCode?: Hex;
  accountAddress?: Address;
  factoryAddress?: Address;
  version?: TLightAccountVersion;
  entryPoint?: EntryPointDef<TEntryPointVersion, Chain>;
};
CreateMultiOwnerModularAccountParams
types.ts
export type CreateMultiOwnerModularAccountParams<
  TTransport extends Transport = Transport,
  TSigner extends SmartAccountSigner = SmartAccountSigner,
  TEntryPointVersion extends "0.6.0" = "0.6.0"
> = Pick<
  ToSmartContractAccountParams<
    "MultiOwnerModularAccount",
    TTransport,
    Chain,
    TEntryPointVersion
  >,
  "transport" | "chain"
> & {
  signer: TSigner;
  salt?: bigint;
  factoryAddress?: Address;
  initCode?: Hex;
  owners?: Address[];
  accountAddress?: Address;
} & EntryPointParameter<TEntryPointVersion, Chain>;

...rest

Omit<
  AlchemySmartAccountClientConfig<
    TTransport,
    TChain,
    SupportedAccount<TAccount>
  >,
  "rpcUrl" | "chain" | "apiKey" | "jwt" | "account"
>;

The remaining parameters that are accepted allow for overriding certain properties of the AlchemySmartAccountClient

AlchemySmartAccountClientConfig
types.ts
// [!include ~/../packages/alchemy/src/client/smartAccountClient.ts:AlchemySmartAccountClientConfig]
 

Return Type

import { type UseSmartAccountClientResult } from "@alchemy/aa-alchemy/react";

client

AlchemySmartAccountClient | undefined Once the underlying account is created, this will be an instance of an AlchemySmartAccountClient connected to an instance of the account type specified.

isLoadingClient

boolean Indicates whether the client is still being created.