JSON RPC
jsonRpcProvider用你指定的 RPC URL 配置 chain。
import { jsonRpcProvider } from 'wagmi/providers/jsonRpc'用法
import { chain, configureChains } from 'wagmi'
import { jsonRpcProvider } from 'wagmi/providers/jsonRpc'
const { chains, publicClient } = configureChains(
[chain.mainnet, chain.polygon],
[
jsonRpcProvider({
rpc: (chain) => ({
http: `https://${chain.id}.example.com`,
}),
}),
],
)返回值
{
chains: Chain[],
publicClient: PublicClient,
webSocketPublicClient: PublicClient
}配置项
rpc
需要填入一个函数,这个函数的接受 chain 作为输入并返回一个 http URL 和 webSocket URL,webSocket URL 不是必须的。
import { chain, configureChains } from 'wagmi'
import { jsonRpcProvider } from 'wagmi/providers/jsonRpc'
const { chains, publicClient } = configureChains(
[chain.mainnet, chain.polygon],
[
jsonRpcProvider({
rpc: (chain) => ({
http: `https://${chain.id}.example.com`,
webSocket: `wss://${chain.id}.example.com`,
}),
}),
],
)