The publicProvider configures the chains with a public RPC URL and also provides an ethers.js getpublicProvider.
Visit ethers.js getpublicProvider
.
import { chain, configureChains } from 'vagmi';import { publicProvider } from 'vagmi/providers/public';const { chains, provider } = configureChains( [chain.mainnet, chain.polygon], [publicProvider()],);
{ chains: Chain[], provider: BaseProvider, webSocketProvider: WebSocketProvider}
The frequency in milliseconds at which the provider polls.
import { chain, configureChains } from 'vagmi';import { publicProvider } from 'vagmi/providers/public';const { chains, provider } = configureChains( [chain.mainnet, chain.polygon], [publicProvider({ pollingInterval: 5000 })],);
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 { publicProvider } from 'vagmi/providers/public';const alchemyId = import.meta.env..ALCHEMY_ID;const { chains, provider } = configureChains( [chain.mainnet, chain.polygon], [ alchemyProvider({ alchemyId, priority: 0 }), publicProvider({ priority: 1 }), ],);
The timeout in milliseconds after which another provider will be attempted.
import { chain, configureChains } from 'vagmi';import { publicProvider } from 'vagmi/providers/public';const alchemyId = import.meta.env..ALCHEMY_ID;const { chains, provider } = configureChains( [chain.mainnet, chain.polygon], [ alchemyProvider({ alchemyId, stallTimeout: 1000 }), publicProvider({ stallTimeout: 1000 }), ],);
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 { publicProvider } from 'vagmi/providers/public';const alchemyId = import.meta.env..ALCHEMY_ID;const { chains, provider } = configureChains( [chain.mainnet, chain.polygon], [alchemyProvider({ alchemyId, weight: 1 }), publicProvider({ weight: 2 })],);