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 { chains, provider } = configureChains(
[chain.mainnet, chain.polygon],
[alchemyProvider({ apiKey: 'yourAlchemyApiKey' })],
)
Return Value
{
chains: Chain[],
provider: AlchemyProvider,
webSocketProvider: AlchemyWebSocketProvider
}
Configuration
apiKey (optional)
Your Alchemy API key from the Alchemy Dashboard.
If no Alchemy API key is provided, it will use the public Alchemy API key. It is recommended to provide your own Alchemy API key to prevent being rate-limited.
import { chain, configureChains } from 'wagmi'
import { alchemyProvider } from 'wagmi/providers/alchemy'
const { chains, provider } = configureChains(
[chain.mainnet, chain.polygon],
[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 { chain, configureChains } from 'wagmi'
import { alchemyProvider } from 'wagmi/providers/alchemy'
import { publicProvider } from 'wagmi/providers/public'
const { chains, provider } = configureChains(
[chain.mainnet, chain.polygon],
[
alchemyProvider({
apiKey: 'yourAlchemyApiKey',
priority: 0,
}),
publicProvider({ 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'
import { publicProvider } from 'wagmi/providers/public'
const { chains, provider } = configureChains(
[chain.mainnet, chain.polygon],
[
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 { chain, configureChains } from 'wagmi'
import { alchemyProvider } from 'wagmi/providers/alchemy'
import { publicProvider } from 'wagmi/providers/public'
const { chains, provider } = configureChains(
[chain.mainnet, chain.polygon],
[
alchemyProvider({
apiKey: 'yourAlchemyApiKey',
weight: 1,
}),
publicProvider({ weight: 2 }),
],
)