The jsonRpcProvider configures the chains with the RPC URLs that you specify and also provides an ethers.js StaticJsonRpcProvider.
Visit ethers.js StaticJsonRpcProvider
.
import { chain, configureChains } from 'vagmi';import { jsonRpcProvider } from 'vagmi/providers/jsonRpc';const { chains, provider } = configureChains( [chain.mainnet, chain.polygon], [ jsonRpcProvider({ rpc: chain => ({ http: `https://${chain.id}.example.com`, }), }), ],);
{ chains: Chain[], provider: JsonRpcProvider, webSocketProvider: WebSocketProvider}
Accepts a function which provides the chain
and expects to receive a http
URL and optionally a webSocket
URL.
import { chain, configureChains } from 'vagmi';import { jsonRpcProvider } from 'vagmi/providers/jsonRpc';const { chains, provider } = configureChains( [chain.mainnet, chain.polygon], [ jsonRpcProvider({ rpc: chain => ({ http: `https://${chain.id}.example.com`, webSocket: `wss://${chain.id}.example.com`, }), }), ],);
The frequency in milliseconds at which the provider polls.
import { chain, configureChains } from 'vagmi';import { jsonRpcProvider } from 'vagmi/providers/jsonRpc';const { chains, provider } = configureChains( [chain.mainnet, chain.polygon], [ jsonRpcProvider({ pollingInterval: 5000, rpc: chain => ({ http: `https://${chain.id}.example.com`, webSocket: `wss://${chain.id}.example.com`, }), }), ],);
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 { jsonRpcProvider } from 'vagmi/providers/jsonRpc';const { chains, provider } = configureChains( [chain.mainnet, chain.polygon], [ jsonRpcProvider({ priority: 0, rpc: chain => ({ http: `https://${chain.id}.example.com`, webSocket: `wss://${chain.id}.example.com`, }), }), alchemyProvider({ priority: 1 }), ],);
The timeout in milliseconds after which another provider will be attempted.
import { chain, configureChains } from 'vagmi';import { jsonRpcProvider } from 'vagmi/providers/jsonRpc';const { chains, provider } = configureChains( [chain.mainnet, chain.polygon], [ jsonRpcProvider({ rpc: chain => ({ http: `https://${chain.id}.example.com`, webSocket: `wss://${chain.id}.example.com`, }), stallTimeout: 1000, }), alchemyProvider({ priority: 1, stallTimeout: 1000 }), ],);
Flag to indicate if the provider should return a StaticJsonRpcProvider
or JsonRpcProvider
. Defaults to true
.
import { chain, configureChains } from 'vagmi';import { jsonRpcProvider } from 'vagmi/providers/jsonRpc';const { chains, provider } = configureChains( [chain.mainnet, chain.polygon], [ jsonRpcProvider({ rpc: chain => ({ http: `https://${chain.id}.example.com`, webSocket: `wss://${chain.id}.example.com`, }), static: false, }), ],);
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 { jsonRpcProvider } from 'vagmi/providers/jsonRpc';const { chains, provider } = configureChains( [chain.mainnet, chain.polygon], [ jsonRpcProvider({ rpc: chain => ({ http: `https://${chain.id}.example.com`, webSocket: `wss://${chain.id}.example.com`, }), weight: 1, }), alchemyProvider({ priority: 1, weight: 2 }), ],);