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.

Import

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

Usage

single-chain.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

import { type CreateConfigProps } from "@alchemy/aa-alchemy/config";
CreateConfigProps
types.ts
export type Connection = ConnectionConfig & {
  chain: Chain;
  gasManagerConfig?: AlchemyGasManagerConfig;
};
 
type RpcConnectionConfig =
  | (Connection & {
      /**
       * 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;
      connections?: never;
    })
  | {
      connections: Connection[];
      chain: Chain;
      /**
       * When providing multiple connections, you must specify the signer connection config
       * to use since the signer is chain agnostic and has a different RPC url.
       */
      signerConnection: ConnectionConfig;
    };
 
export type CreateConfigProps = RpcConnectionConfig & {
  chain: Chain;
  sessionConfig?: AlchemySignerParams["sessionConfig"];
  /**
   * 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;
 
  connectors?: CreateConnectorFn[];
} & Omit<
    PartialBy<
      Exclude<AlchemySignerParams["client"], AlchemySignerClient>,
      "iframeConfig"
    >,
    "connection"
  >;
ConnectionConfig
types.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

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.