From 642f6cad6036565cca90a7ab4f060cf9f50a6724 Mon Sep 17 00:00:00 2001 From: Kilter Date: Mon, 11 Nov 2024 09:10:59 -0500 Subject: [PATCH] adding transport for all supported chains --- src/lib/network.ts | 22 ++++++++++++++++++++++ src/wagmiConfigs.ts | 14 +++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/lib/network.ts b/src/lib/network.ts index 91fd606fef..84ebc1a7ee 100644 --- a/src/lib/network.ts +++ b/src/lib/network.ts @@ -19,3 +19,25 @@ export const getChainName = (chainId?: number, chainType?: ChainType) => { ]?.name || unknown ); }; + +// Network mapping for DRPC +export const getDrpcNetwork = (chainId: number): string | null => { + const networkMap: { [key: number]: string } = { + 1: 'ethereum', + 137: 'polygon', + 10: 'optimism', + 42161: 'arbitrum', + 8453: 'base', + 42220: 'celo', + 100: 'gnosis', + 1101: 'polygon-zkevm', + 11155111: 'sepolia', + 11155420: 'optimism-sepolia', + 421614: 'arbitrum-sepolia', + 84532: 'base-sepolia', + 44787: 'celo-alfajores', + 1442: 'polygon-zkevm-cardona', + }; + + return networkMap[chainId] || null; +}; diff --git a/src/wagmiConfigs.ts b/src/wagmiConfigs.ts index 03c50ba47a..f87be44fbb 100644 --- a/src/wagmiConfigs.ts +++ b/src/wagmiConfigs.ts @@ -2,6 +2,7 @@ import { cookieStorage, createConfig, createStorage } from 'wagmi'; import { walletConnect, coinbaseWallet, safe } from '@wagmi/connectors'; import { createClient, http } from 'viem'; +import { getDrpcNetwork } from './lib/network'; import configuration from './configuration'; // Get projectId at https://cloud.walletconnect.com @@ -19,6 +20,14 @@ const metadata = { const chains = configuration.EVM_CHAINS; +const createDrpcTransport = (chainId: number) => { + const network = getDrpcNetwork(chainId); + const drpcKey = process.env.NEXT_PUBLIC_DRPC_KEY; + return network && drpcKey + ? http(`https://lb.drpc.org/ogrpc?network=${network}&dkey=${drpcKey}`) + : http(); +}; + // Create wagmiConfig export const wagmiConfig = createConfig({ chains: chains, // required @@ -37,6 +46,9 @@ export const wagmiConfig = createConfig({ storage: cookieStorage, }), client({ chain }) { - return createClient({ chain, transport: http() }); + return createClient({ + chain, + transport: createDrpcTransport(chain.id), + }); }, });