• Core
  • Providers
  • Alchemy

Alchemy

The alchemyProvider configures the chains with Alchemy RPC URLs and also provides an ethers.js AlchemyProvider.

import { alchemyProvider } from '@wagmi/core/providers/alchemy'

Usage

import { configureChains } from '@wagmi/core'
import { mainnet, optimism, polygon } from '@wagmi/core/chains'
import { alchemyProvider } from '@wagmi/core/providers/alchemy'
 
const { chains, provider } = configureChains(
  [mainnet, optimism, polygon],
  [alchemyProvider({ apiKey: 'yourAlchemyApiKey' })],
)

Note: The above example is using chains from @wagmi/core/chains.

Return Value

{
  chains: Chain[],
  provider: AlchemyProvider,
  webSocketProvider: AlchemyWebSocketProvider
}

Configuration

apiKey

Your Alchemy API key from the Alchemy Dashboard.

import { configureChains, mainnet } from '@wagmi/core'
import { alchemyProvider } from '@wagmi/core/providers/alchemy'
 
const { chains, provider } = configureChains(
  [mainnet],
  [alchemyProvider({ apiKey: 'yourAlchemyApiKey' })],
)

priority (optional)

The priority used for the provider. Lower-value priorities are favoured over higher-value priorities. If multiple providers share the same priority, they are chosen at random.

import { configureChains, mainnet } from '@wagmi/core'
import { alchemyProvider } from '@wagmi/core/providers/alchemy'
import { publicProvider } from '@wagmi/core/providers/public'
 
const { chains, provider } = configureChains(
  [mainnet],
  [
    alchemyProvider({
      apiKey: 'yourAlchemyApiKey',
      priority: 0,
    }),
    publicProvider({ priority: 1 }),
  ],
)

stallTimeout (optional)

The timeout in milliseconds after which another provider will be attempted.

import { configureChains, mainnet } from '@wagmi/core'
import { alchemyProvider } from '@wagmi/core/providers/alchemy'
import { publicProvider } from '@wagmi/core/providers/public'
 
const { chains, provider } = configureChains(
  [mainnet],
  [
    alchemyProvider({
      apiKey: 'yourAlchemyApiKey',
      stallTimeout: 1_000,
    }),
    publicProvider(),
  ],
)

weight (optional)

The weight a response from this provider provides. This can be used if a given provider is more trusted.

import { configureChains, mainnet } from '@wagmi/core'
import { alchemyProvider } from '@wagmi/core/providers/alchemy'
import { publicProvider } from '@wagmi/core/providers/public'
 
const { chains, provider } = configureChains(
  [mainnet],
  [
    alchemyProvider({
      apiKey: 'yourAlchemyApiKey',
      weight: 1,
    }),
    publicProvider({ weight: 2 }),
  ],
)