Skip to content
Docs
/
Providers
/
JSON RPC

JSON RPC

The staticJsonRpcProvider configures the chains with the RPC URLs that you specify and also provides an ethers.js StaticJsonRpcProvider.

import { staticJsonRpcProvider } from 'wagmi/providers/staticJsonRpc'

Usage

import { chain, configureChains } from 'wagmi'
import { staticJsonRpcProvider } from 'wagmi/providers/staticJsonRpc'

const { chains, provider } = configureChains(
  [chain.mainnet, chain.polygon],
  [
    staticJsonRpcProvider({
      rpcUrls: (chain) => ({
        rpcUrl: `https://${chain.id}.example.com`,
      }),
    }),
  ],
)

Return Value

{
  chains: Chain[],
  provider: StaticJsonRpcProvider,
  webSocketProvider: WebSocketProvider
}

Configuration

rpcUrls

Accepts a function which provides the chain and expects to receive an rpcUrl and optionally a webSocketRpcUrl.

import { chain, configureChains } from 'wagmi'
import { staticJsonRpcProvider } from 'wagmi/providers/staticJsonRpc'

const { chains, provider } = configureChains(
  [chain.mainnet, chain.polygon],
  [
    staticJsonRpcProvider({
      rpcUrls: (chain) => ({
        rpcUrl: `https://${chain.id}.example.com`,
        webSocketRpcUrl: `wss://${chain.id}.example.com`,
      }),
    }),
  ],
)