From 904f35a202b959c8eea377ed4efd1a53dd35c760 Mon Sep 17 00:00:00 2001 From: Onah Prosper Date: Wed, 25 Mar 2026 06:04:53 +0000 Subject: [PATCH] refactor: enhance SUPPORTED_CHAINS structure and RPC URL handling * Updated the SUPPORTED_CHAINS object to include network names for better clarity. * Refactored the parseRpcUrl function to utilize dynamic RPC URLs based on the network name, improving configurability and error handling. --- app/lib/bundler/chains.ts | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/app/lib/bundler/chains.ts b/app/lib/bundler/chains.ts index b56a045b..31dff6cc 100644 --- a/app/lib/bundler/chains.ts +++ b/app/lib/bundler/chains.ts @@ -5,15 +5,16 @@ import { createPublicClient, createWalletClient, http, type PublicClient, type WalletClient } from 'viem'; import { privateKeyToAccount } from 'viem/accounts'; import { bsc, base, arbitrum, polygon, mainnet, lisk, celo, type Chain } from 'viem/chains'; +import { getRpcUrl } from '@/app/utils'; -const SUPPORTED_CHAINS: Record = { - [bsc.id]: { chain: bsc, envKey: 'BSC' }, - [base.id]: { chain: base, envKey: 'BASE' }, - [arbitrum.id]: { chain: arbitrum, envKey: 'ARB' }, - [polygon.id]: { chain: polygon, envKey: 'POLYGON' }, - [mainnet.id]: { chain: mainnet, envKey: 'ETHEREUM' }, - [lisk.id]: { chain: lisk, envKey: 'LISK' }, - [celo.id]: { chain: celo, envKey: 'CELO' }, +const SUPPORTED_CHAINS: Record = { + [bsc.id]: { chain: bsc, envKey: 'BSC', networkName: 'BNB Smart Chain' }, + [base.id]: { chain: base, envKey: 'BASE', networkName: 'Base' }, + [arbitrum.id]: { chain: arbitrum, envKey: 'ARB', networkName: 'Arbitrum One' }, + [polygon.id]: { chain: polygon, envKey: 'POLYGON', networkName: 'Polygon' }, + [mainnet.id]: { chain: mainnet, envKey: 'ETHEREUM', networkName: 'Ethereum' }, + [lisk.id]: { chain: lisk, envKey: 'LISK', networkName: 'Lisk' }, + [celo.id]: { chain: celo, envKey: 'CELO', networkName: 'Celo' }, }; export function parseChainId(value: unknown): number { @@ -41,11 +42,11 @@ export function parseRpcUrl(chainId: number): string { if (!entry) { throw new Error(`Unsupported chainId: ${chainId}. Supported: ${Object.keys(SUPPORTED_CHAINS).join(', ')}`); } - const clientId = process.env.NEXT_PUBLIC_THIRDWEB_CLIENT_ID?.trim(); - if (!clientId) { - throw new Error('NEXT_PUBLIC_THIRDWEB_CLIENT_ID is required for bundler RPC'); + const rpcUrl = getRpcUrl(entry.networkName); + if (!rpcUrl) { + throw new Error(`No RPC URL configured for network: ${entry.networkName}`); } - return `https://${chainId}.rpc.thirdweb.com/${clientId}`; + return rpcUrl; } function getSponsorPrivateKey(): `0x${string}` {