Infura
The infuraProvider
configures the chains with Infura RPC URLs and also provides an ethers.js InfuraProvider
.
import { infuraProvider } from 'wagmi/providers/infura'
Usage
import { chain, configureChains } from 'wagmi'
import { infuraProvider } from 'wagmi/providers/infura'
const infuraId = process.env.INFURA_ID
const { chains, provider } = configureChains(
[chain.mainnet, chain.polygon],
[infuraProvider({ infuraId })],
)
Return Value
{
chains: Chain[],
provider: InfuraProvider,
webSocketProvider: InfuraWebSocketProvider
}
Configuration
infuraId (optional)
Your Infura ID from the Infura Dashboard.
If no Infura ID is provided, it will use the public Infura ID. It is recommended to provide your own Infura ID to prevent being rate-limited.
import { chain, configureChains } from 'wagmi'
import { infuraProvider } from 'wagmi/providers/infura'
const infuraId = process.env.INFURA_ID
const { chains, provider } = configureChains(
[chain.mainnet, chain.polygon],
[infuraProvider({ infuraId })],
)
pollingInterval (optional)
The frequency in milliseconds at which the provider polls.
import { chain, configureChains } from 'wagmi'
import { infuraProvider } from 'wagmi/providers/infura'
const infuraId = process.env.INFURA_ID
const { chains, provider } = configureChains(
[chain.mainnet, chain.polygon],
[infuraProvider({ infuraId, 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 { infuraProvider } from 'wagmi/providers/infura'
const alchemyId = process.env.ALCHEMY_ID
const infuraId = process.env.INFURA_ID
const { chains, provider } = configureChains(
[chain.mainnet, chain.polygon],
[
infuraProvider({ infuraId, priority: 0 }),
alchemyProvider({ alchemyId, priority: 1 }),
],
)
stallTimeout (optional)
The timeout in milliseconds after which another provider will be attempted.
import { chain, configureChains } from 'wagmi'
import { infuraProvider } from 'wagmi/providers/infura'
const alchemyId = process.env.ALCHEMY_ID
const infuraId = process.env.INFURA_ID
const { chains, provider } = configureChains(
[chain.mainnet, chain.polygon],
[
infuraProvider({ infuraId, stallTimeout: 1000 }),
alchemyProvider({ alchemyId, 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 { infuraProvider } from 'wagmi/providers/infura'
const alchemyId = process.env.ALCHEMY_ID
const infuraId = process.env.INFURA_ID
const { chains, provider } = configureChains(
[chain.mainnet, chain.polygon],
[
infuraProvider({ infuraId, weight: 1 }),
alchemyProvider({ alchemyId, weight: 2 }),
],
)