Returns a KV object with chainIds' keyed to HTTP transport URLs. This allows users to specify custom RPC URLs instead of always using the default public ones.
/* src/utils/getRpcUrls */import { Rule } from"../types/block3d";import { type Config } from"wagmi";import { getClient } from"@wagmi/core";interfaceRpcUrls { [chainId:number]:string;}/** * @dev This function views the wagmi config and retrieves any necessary provided * RPC URLs, if none are provided we use the default values * @param rules is an array of valid rule types * @param wagmiConig is the current wagmi config object * @return `rpcUrls` is an KV object with chainIds mapped to RPC URLs */exportasyncfunctiongetRpcUrls(rules:Rule[], wagmiConfig:Config) {/* Step 1: Use Set to store only unique chainIds */constchainIds=newSet<number>();rules.forEach((rule) => {if (rule.contracts) {rule?.contracts.forEach((contract) => {chainIds.add(contract.chainId); }); } });constchainIdsArray=Array.from(chainIds);/* Step 2: View RPC URLs and add them to KV object */let rpcUrls:RpcUrls= {};chainIdsArray.forEach(async (chainId) => {constclient=awaitgetClient(wagmiConfig, { chainId: chainId, });consturl=client?.transport.url;if (url) { rpcUrls[chainId] = url; } });/* Step 3: Return the KV object */return rpcUrls;}