Infura
The infuraProvider
configures the chains with Infura RPC URLs and also provides an ethers.js InfuraProvider
.
import { infuraProvider } from '@wagmi/core/providers/infura'
Usage
import { configureChains } from '@wagmi/core'
import { mainnet, polygon } from '@wagmi/core/chains'
import { infuraProvider } from '@wagmi/core/providers/infura'
const { chains, provider } = configureChains(
[mainnet, polygon],
[infuraProvider({ apiKey: 'yourInfuraApiKey' })],
)
Note: The above example is using chains from @wagmi/core/chains
.
Return Value
{
chains: Chain[],
provider: InfuraProvider,
webSocketProvider: InfuraWebSocketProvider
}
Configuration
apiKey
Your Infura API key from the Infura Dashboard.
import { configureChains } from '@wagmi/core'
import { mainnet, polygon } from '@wagmi/core/chains'
import { infuraProvider } from '@wagmi/core/providers/infura'
const { chains, provider } = configureChains(
[mainnet, polygon],
[infuraProvider({ apiKey: 'yourInfuraApiKey' })],
)
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 } from '@wagmi/core'
import { mainnet, polygon }, from '@wagmi/core/chains'
import { infuraProvider } from '@wagmi/core/providers/infura'
import { publicProvider } from '@wagmi/core/providers/public'
const { chains, provider } = configureChains(
[mainnet, polygon],
[
infuraProvider({
apiKey: 'yourInfuraApiKey',
priority: 0,
}),
publicProvider({ priority: 1 }),
],
)
stallTimeout (optional)
The timeout in milliseconds after which another provider will be attempted.
import { configureChains } from '@wagmi/core'
import { mainnet, polygon } from '@wagmi/core/chains'
import { infuraProvider } from '@wagmi/core/providers/infura'
import { publicProvider } from '@wagmi/core/providers/public'
const { chains, provider } = configureChains(
[mainnet, polygon],
[
infuraProvider({
apiKey: 'yourInfuraApiKey',
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 } from '@wagmi/core'
import { mainnet, polygon } from '@wagmi/core/chains'
import { infuraProvider } from '@wagmi/core/providers/infura'
import { publicProvider } from '@wagmi/core/providers/public'
const { chains, provider } = configureChains(
[mainnet, polygon],
[
infuraProvider({
apiKey: 'yourInfuraApiKey',
weight: 1,
}),
publicProvider({ weight: 2 }),
],
)