Skip to content
Docs
Providers
Alchemy

Alchemy

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

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

Usage

import { chain, configureChains } from 'wagmi'
import { alchemyProvider } from 'wagmi/providers/alchemy'

const alchemyId = process.env.ALCHEMY_ID

const { chains, provider } = configureChains(
  [chain.mainnet, chain.polygon],
  [alchemyProvider({ alchemyId })],
)

Return Value

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

Configuration

alchemyId (optional)

Your Alchemy ID from the Alchemy Dashboard.

If no Alchemy ID is provided, it will use the public Alchemy ID. It is recommended to provide your own Alchemy ID to prevent being rate-limited.

import { chain, configureChains } from 'wagmi'
import { alchemyProvider } from 'wagmi/providers/alchemy'

const alchemyId = process.env.ALCHEMY_ID

const { chains, provider } = configureChains(
  [chain.mainnet, chain.polygon],
  [alchemyProvider({ alchemyId })],
)

pollingInterval (optional)

The frequency in milliseconds at which the provider polls.

import { chain, configureChains } from 'wagmi'
import { alchemyProvider } from 'wagmi/providers/alchemy'

const alchemyId = process.env.ALCHEMY_ID

const { chains, provider } = configureChains(
  [chain.mainnet, chain.polygon],
  [alchemyProvider({ alchemyId, pollingInterval: 5000 })],
)

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 { chain, configureChains } from 'wagmi'
import { alchemyProvider } from 'wagmi/providers/alchemy'

const alchemyId = process.env.ALCHEMY_ID
const infuraId = process.env.INFURA_ID

const { chains, provider } = configureChains(
  [chain.mainnet, chain.polygon],
  [
    alchemyProvider({ alchemyId, priority: 0 }),
    infuraProvider({ infuraId, priority: 1 }),
  ],
)

stallTimeout (optional)

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

import { chain, configureChains } from 'wagmi'
import { alchemyProvider } from 'wagmi/providers/alchemy'

const alchemyId = process.env.ALCHEMY_ID
const infuraId = process.env.INFURA_ID

const { chains, provider } = configureChains(
  [chain.mainnet, chain.polygon],
  [
    alchemyProvider({ alchemyId, stallTimeout: 1000 }),
    infuraProvider({ infuraId, stallTimeout: 1000 }),
  ],
)

weight (optional)

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

import { chain, configureChains } from 'wagmi'
import { alchemyProvider } from 'wagmi/providers/alchemy'

const alchemyId = process.env.ALCHEMY_ID
const infuraId = process.env.INFURA_ID

const { chains, provider } = configureChains(
  [chain.mainnet, chain.polygon],
  [
    alchemyProvider({ alchemyId, weight: 1 }),
    infuraProvider({ infuraId, weight: 2 }),
  ],
)