Skip to content

createConfig

The createConfig method is used to create a configuration object that is used to initialize the AlchemyAccountProvider. The output of this function contains all of the state that will be used by the various hooks exported by @alchemy/aa-alchemy/react.

WARNING

It's not recommended to use the resulting config directly. However, if you are not using React it is possible to build your own custom hooks using the state contained in the config object.

Import

ts
import { createConfig } from "@alchemy/aa-alchemy/config";

Usage

ts
import { createConfig } from "@alchemy/aa-alchemy/config";
import { sepolia } from "@alchemy/aa-core";

export const config = createConfig({
  // required
  rpcUrl: "/api/rpc",
  chain: sepolia,
});

Parameters

ts
import { type CreateConfigProps } from "@alchemy/aa-alchemy/config";
CreateConfigProps
ts
export type CreateConfigProps = ConnectionConfig & {
  chain: Chain;
  sessionConfig?: AlchemySignerParams["sessionConfig"];
  /**
   * Optional parameter that allows you to specify a different RPC Url
   * or connection to be used specifically by the signer.
   * This is useful if you have a different backend proxy for the signer
   * than for your Bundler or Node RPC calls.
   */
  signerConnection?: ConnectionConfig;
  /**
   * Enable this parameter if you are using the config in an SSR setting (eg. NextJS)
   * Turing this setting on will disable automatic hydration of the client store
   */
  ssr?: boolean;

  // TODO: should probably abstract this out into a function
  storage?: (config?: { sessionLength: number }) => Storage;
} & Omit<
    PartialBy<
      Exclude<AlchemySignerParams["client"], AlchemySignerClient>,
      "iframeConfig"
    >,
    "connection"
  >;
ConnectionConfig
ts
export const ConnectionConfigSchema = z.union([
  z.object({
    rpcUrl: z.never().optional(),
    apiKey: z.string(),
    jwt: z.never().optional(),
  }),
  z.object({
    rpcUrl: z.never().optional(),
    apiKey: z.never().optional(),
    jwt: z.string(),
  }),
  z.object({
    rpcUrl: z.string(),
    apiKey: z.never().optional(),
    jwt: z.never().optional(),
  }),
  z.object({
    rpcUrl: z.string(),
    apiKey: z.never().optional(),
    jwt: z.string(),
  }),
]);

Return Type

ts
import { type AlchemyAccountsConfig } from "@alchemy/aa-alchemy/config";

Returns an object containing the Alchemy Accounts state.

coreStore

CoreStore This store contains all of the state that can be used on either the client or the server.

clientStore

ClientStore This store contains only the state available on the client.