Public
The publicProvider
configures the chains with a public RPC URL and also provides an ethers.js getpublicProvider
.
import { publicProvider } from '@wagmi/core/providers/public'
Usage
import { configureChains } from '@wagmi/core'
import { mainnet, polygon } from '@wagmi/core/chains'
import { publicProvider } from '@wagmi/core/providers/public'
const { chains, provider } = configureChains(
[mainnet, polygon],
[publicProvider()],
)
Note: The above example is using chains from @wagmi/core/chains
.
Only having publicProvider
in your providers will make the chain use the
public RPC URL which could lead to rate-limiting. It is recommended to also
include another provider in your list (such as: alchemyProvider
,
infuraProvider
or jsonRpcProvider
).
Return Value
{
chains: Chain[],
provider: BaseProvider,
webSocketProvider: WebSocketProvider
}
Configuration
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 { publicProvider } from '@wagmi/core/providers/public'
const { chains, provider } = configureChains(
[mainnet, polygon],
[
alchemyProvider({ apiKey: 'yourAlchemyApiKey', 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 { publicProvider } from '@wagmi/core/providers/public'
const { chains, provider } = configureChains(
[mainnet, polygon],
[
alchemyProvider({ apiKey: 'yourAlchemyApiKey' }),
publicProvider({ stallTimeout: 1_000 }),
],
)
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 { publicProvider } from '@wagmi/core/providers/public'
const { chains, provider } = configureChains(
[mainnet, polygon],
[
alchemyProvider({ apiKey: 'yourAlchemyApiKey', weight: 1 }),
publicProvider({ weight: 2 }),
],
)