Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
# This file is autogenerated
title: AlchemyProvider
description: Overview of the AlchemyProvider method
Copy link

Copilot AI Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description refers to AlchemyProvider as a 'method' but it's actually a React component. Should be 'Overview of the AlchemyProvider component' to be technically accurate.

Copilot generated this review using guidance from repository custom instructions.
slug: wallets/reference/alchemy/react/components/AlchemyProvider
---

AlchemyProvider component that wraps the necessary providers for Alchemy functionality

This component:

- Wraps WagmiProvider with the wagmi config from createAlchemyConfig
- Will wrap additional providers in the future (Solana, UI, etc.)

## Import

```ts
import { AlchemyProvider } from "@alchemy/react";
```

## Usage

```tsx
import { AlchemyProvider, createAlchemyConfig } from "@alchemy/react";
import { arbitrumSepolia, sepolia } from "wagmi/chains";

const config = createAlchemyConfig({
apiKey: process.env.NEXT_PUBLIC_ALCHEMY_API_KEY!,
chains: [arbitrumSepolia, sepolia],
});

export function App({ children }) {
return <AlchemyProvider config={config}>{children}</AlchemyProvider>;
}
```

## Parameters

### props

`AlchemyProviderProps`

- The props for the AlchemyProvider component

### props.config

`AlchemyReactConfig`

- The Alchemy configuration object created by createAlchemyConfig

### props.children

`ReactNode`

- Child components to render

## Returns

`JSX.Element`
The wrapped React components with Alchemy providers
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
# This file is autogenerated
title: createAlchemyConfig
description: Overview of the createAlchemyConfig method
Copy link

Copilot AI Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description refers to createAlchemyConfig as a 'method' but it's actually a function. Should be 'Overview of the createAlchemyConfig function' to be technically accurate.

Copilot generated this review using guidance from repository custom instructions.
slug: wallets/reference/alchemy/react/functions/createAlchemyConfig
---

Creates a simplified Alchemy configuration for React applications

This function removes the boilerplate of setting up wagmi with Alchemy by:

- Automatically configuring Alchemy transport for each chain
- Automatically adding Alchemy auth connector
- Providing sensible defaults
- Offering escape hatches for advanced customization

## Import

```ts
import { createAlchemyConfig } from "@alchemy/react";
```

## Usage

```tsx
import { createAlchemyConfig } from "@alchemy/react";
import { arbitrumSepolia, sepolia } from "wagmi/chains";

const config = createAlchemyConfig({
apiKey: process.env.NEXT_PUBLIC_ALCHEMY_API_KEY!,
chains: [arbitrumSepolia, sepolia],
});

// Use with AlchemyProvider or WagmiProvider
<AlchemyProvider config={config}>{children}</AlchemyProvider>;
```

## Parameters

### options

`CreateAlchemyConfigOptions`

- Configuration options for the Alchemy config

## Returns

`AlchemyReactConfig`
AlchemyReactConfig object containing the wagmi config
20 changes: 3 additions & 17 deletions examples/react-v5-example/src/app/config.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
import { createConfig } from "wagmi";
import { arbitrumSepolia, sepolia } from "wagmi/chains";
import { alchemyAuth } from "@alchemy/connectors-web";
import { alchemyTransport } from "@alchemy/common";
import { createAlchemyConfig } from "@alchemy/react";

export const config = createConfig({
connectors: [
alchemyAuth({
apiKey: process.env.NEXT_PUBLIC_ALCHEMY_API_KEY,
}),
],
export const config = createAlchemyConfig({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

beautiful

apiKey: process.env.NEXT_PUBLIC_ALCHEMY_API_KEY,
chains: [arbitrumSepolia, sepolia],
transports: {
[arbitrumSepolia.id]: alchemyTransport({
apiKey: process.env.NEXT_PUBLIC_ALCHEMY_API_KEY,
}),
[sepolia.id]: alchemyTransport({
apiKey: process.env.NEXT_PUBLIC_ALCHEMY_API_KEY,
}),
},
});
6 changes: 3 additions & 3 deletions examples/react-v5-example/src/app/providers.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
"use client";

import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { WagmiProvider } from "wagmi";
import { AlchemyProvider } from "@alchemy/react";
import { config } from "./config.ts";
import { ReactNode } from "react";

const queryClient = new QueryClient();

export const Providers = ({ children }: { children: ReactNode }) => {
return (
<WagmiProvider config={config}>
<AlchemyProvider config={config}>
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
</WagmiProvider>
</AlchemyProvider>
);
};
1 change: 1 addition & 0 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
},
"dependencies": {
"@alchemy/common": "*",
"@alchemy/connectors-web": "*",
"@alchemy/wagmi-core": "*"
},
"peerDependencies": {
Expand Down
57 changes: 57 additions & 0 deletions packages/react/src/AlchemyProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"use client";

import { type ReactNode } from "react";
import { WagmiProvider } from "wagmi";
import type { AlchemyReactConfig } from "./createAlchemyConfig.js";

/**
* Props for the AlchemyProvider component
*/
export type AlchemyProviderProps = {
/** The Alchemy configuration object created by createAlchemyConfig */
config: AlchemyReactConfig;
/** Child components to render */
children: ReactNode;
};

/**
* AlchemyProvider component that wraps the necessary providers for Alchemy functionality
*
* This component:
* - Wraps WagmiProvider with the wagmi config from createAlchemyConfig
* - Will wrap additional providers in the future (Solana, UI, etc.)
*
* @param {AlchemyProviderProps} props - The props for the AlchemyProvider component
* @param {AlchemyReactConfig} props.config - The Alchemy configuration object created by createAlchemyConfig
* @param {ReactNode} props.children - Child components to render
* @returns {JSX.Element} The wrapped React components with Alchemy providers
*
* @example
* ```tsx
* import { AlchemyProvider, createAlchemyConfig } from "@alchemy/react";
* import { arbitrumSepolia, sepolia } from "wagmi/chains";
*
* const config = createAlchemyConfig({
* apiKey: process.env.NEXT_PUBLIC_ALCHEMY_API_KEY!,
* chains: [arbitrumSepolia, sepolia],
* });
*
* export function App({ children }) {
* return (
* <AlchemyProvider config={config}>
* {children}
* </AlchemyProvider>
* );
* }
* ```
*/
export function AlchemyProvider({ config, children }: AlchemyProviderProps) {
return (
<WagmiProvider config={config.wagmi}>
{children}
{/* Future: Additional providers will be added here */}
{/* e.g., <AlchemySolanaProvider config={config.solana}> */}
{/* e.g., <AlchemyUIProvider config={config.ui}> */}
</WagmiProvider>
);
}
135 changes: 135 additions & 0 deletions packages/react/src/createAlchemyConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import { alchemyTransport } from "@alchemy/common";
import { alchemyAuth } from "@alchemy/connectors-web";
import { createConfig, type CreateConfigParameters, type Config } from "wagmi";
import type { Chain } from "viem";

/**
* Configuration options for creating an Alchemy config
*/
export type CreateAlchemyConfigOptions = {
/**
* Alchemy API key for authentication and transport
*/
apiKey?: string;

/**
* Alchemy JWT for authentication and transport
*/
jwt?: string;

/**
* Custom RPC URL for transport
*/
url?: string;

/**
* List of EVM chains to support
*/
chains: [Chain, ...Chain[]];

/**
* Policy IDs for gas sponsorship (optional)
*/
policyIds?: string[];

/**
* Enable server-side rendering support (optional)
*/
ssr?: boolean;
};

/**
* Return type for createAlchemyConfig
*/
export type AlchemyReactConfig = {
/** Wagmi config for use with WagmiProvider */
wagmi: Config;

// Future extensions (not implemented in M2):
// solana?: AlchemySolanaConfig;
// ui?: AlchemyUIConfig;
};

/**
* Creates a simplified Alchemy configuration for React applications
*
* This function removes the boilerplate of setting up wagmi with Alchemy by:
* - Automatically configuring Alchemy transport for each chain
* - Automatically adding Alchemy auth connector
* - Providing sensible defaults
* - Offering escape hatches for advanced customization
*
* @example
* ```tsx
* import { createAlchemyConfig } from "@alchemy/react";
* import { arbitrumSepolia, sepolia } from "wagmi/chains";
*
* const config = createAlchemyConfig({
* apiKey: process.env.NEXT_PUBLIC_ALCHEMY_API_KEY!,
* chains: [arbitrumSepolia, sepolia],
* });
*
* // Use with AlchemyProvider or WagmiProvider
* <AlchemyProvider config={config}>
* {children}
* </AlchemyProvider>
* ```
*
* @param {CreateAlchemyConfigOptions} options - Configuration options for the Alchemy config
* @returns {AlchemyReactConfig} AlchemyReactConfig object containing the wagmi config
*/
export function createAlchemyConfig(
options: CreateAlchemyConfigOptions,
): AlchemyReactConfig {
const {
apiKey,
jwt,
url,
chains,
// policyIds, // TODO: add when smart wallet becomes default
ssr = false,
} = options;

if (!chains?.length) {
Copy link

Copilot AI Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The optional chaining ?. is unnecessary here since chains is a required parameter with type [Chain, ...Chain[]]. This will always be defined and have at least one element due to the type constraint.

Suggested change
if (!chains?.length) {
if (!chains.length) {

Copilot uses AI. Check for mistakes.
throw new Error("createAlchemyConfig requires at least one EVM chain.");
}

// If the caller didn't provide custom transports, we will build them.
if (!apiKey && !jwt && !url) {
throw new Error("createAlchemyConfig requires apiKey, jwt, or url.");
}

// Build transports from chains when needed.
const transports: CreateConfigParameters["transports"] = (() => {
const baseInit = {
...(apiKey && { apiKey }),
...(jwt && { jwt }),
...(url && { url }),
};
const perChain: NonNullable<CreateConfigParameters["transports"]> = {};
for (const chain of chains) {
perChain[chain.id] = alchemyTransport(baseInit);
}
return perChain;
})();

// TODO(v5): Currently using alchemyAuth; swap to alchemySmartWallet when ready.
const defaultConnectors = [
// Currently alchemyAuth only supports apiKey
...(apiKey ? [alchemyAuth({ apiKey })] : []),
];

const wagmiConfig = createConfig({
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up not implementing the wagmiOverrides option in this PR. I wanted to get some opinions on it. I struggled getting the types to work for some reason, I kept getting a type error when doing a shallow copy into the params.

It got me thinking, I wonder if we should just try to expose options that we see fit (rather than a full wagmiOverrides option. And if anyone needs a bunch of wagmi overrides, we just recommend they build the wagmi config themselves.

chains,
transports,
connectors: defaultConnectors,
ssr,
});

// Return structured config for future extensibility
return {
wagmi: wagmiConfig,
// Future: solana config
// Future: ui config
};
}
12 changes: 12 additions & 0 deletions packages/react/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
// Hooks
export type * from "./hooks/useSendEmailOtp.js";
export { useSendEmailOtp } from "./hooks/useSendEmailOtp.js";
export type * from "./hooks/useSubmitOtpCode.js";
export { useSubmitOtpCode } from "./hooks/useSubmitOtpCode.js";

// Configuration
export type {
CreateAlchemyConfigOptions,
AlchemyReactConfig,
} from "./createAlchemyConfig.js";
export { createAlchemyConfig } from "./createAlchemyConfig.js";

// Providers
export type { AlchemyProviderProps } from "./AlchemyProvider.js";
export { AlchemyProvider } from "./AlchemyProvider.js";
Loading
Loading