Infura

The infuraProvider configures the chains with Infura RPC URLs and also provides an ethers.js InfuraProvider.


Visit ethers.js InfuraProvider.

Usage

import { chain, configureChains } from 'vagmi';import { infuraProvider } from 'vagmi/providers/infura';const infuraId = import.meta.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 'vagmi';import { infuraProvider } from 'vagmi/providers/infura';const infuraId = import.meta.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 'vagmi';import { infuraProvider } from 'vagmi/providers/infura';const infuraId = import.meta.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 'vagmi';import { infuraProvider } from 'vagmi/providers/infura';const alchemyId = import.meta.env.ALCHEMY_ID;const infuraId = import.meta.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 'vagmi';import { infuraProvider } from 'vagmi/providers/infura';const alchemyId = import.meta.env.ALCHEMY_ID;const infuraId = import.meta.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 'vagmi';import { infuraProvider } from 'vagmi/providers/infura';const alchemyId = import.meta.env.ALCHEMY_ID;const infuraId = import.meta.env.INFURA_ID;const { chains, provider } = configureChains(  [chain.mainnet, chain.polygon],  [    infuraProvider({ infuraId, weight: 1 }),    alchemyProvider({ alchemyId, weight: 2 }),  ],);