File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77 http ,
88} from 'viem' ;
99import { gnosis } from 'viem/chains' ;
10+ import { getRpcUrlsForChain } from '@/app/wagmi' ;
1011
1112// Global state for custom RPC URL
1213let globalCustomRpcUrl : string | undefined = undefined ;
@@ -297,20 +298,16 @@ export const getGnosisPublicClient = (rpcIndex: number = 0) => {
297298 // Use global custom RPC URL if set, otherwise fall back to env variable
298299 const envRpcUrl = process . env . NEXT_PUBLIC_GNOSIS_RPC ;
299300
300- // Public fallback RPC URLs in order of preference
301- const fallbackRpcs = [
302- 'https://rpc.gnosischain.com' ,
303- 'https://gnosis-mainnet.public.blastapi.io' ,
304- 'https://gnosis.drpc.org' ,
305- ] ;
301+ // Same RPC list as wagmi (single source of truth; no duplicate list here)
302+ const fallbackRpcs = getRpcUrlsForChain ( gnosis . id ) ! ;
306303
307- let rpcUrl ;
304+ let rpcUrl : string ;
308305 if ( rpcIndex === 0 ) {
309306 // Primary attempt: use custom/env RPC or first fallback
310307 rpcUrl = globalCustomRpcUrl || envRpcUrl || fallbackRpcs [ 0 ] ;
311308 } else {
312309 // Fallback attempts: use specific fallback RPC
313- rpcUrl = fallbackRpcs [ rpcIndex ] || fallbackRpcs [ fallbackRpcs . length - 1 ] ;
310+ rpcUrl = fallbackRpcs [ rpcIndex ] ?? fallbackRpcs [ fallbackRpcs . length - 1 ] ;
314311 }
315312
316313 // We are using public RPC for the Gnosis chain unless a custom RPC is set or env variable is set
Original file line number Diff line number Diff line change @@ -209,6 +209,14 @@ const CHAIN_POLLING_INTERVALS: Record<number, number> = {
209209
210210const DEFAULT_POLLING_INTERVAL = 4_000 ;
211211
212+ /**
213+ * Returns the RPC URL list for a chain (same order as wagmi transport fallbacks).
214+ * Use this so Gnosis and other chain RPCs stay in sync with wagmi config.
215+ */
216+ export function getRpcUrlsForChain ( chainId : number ) : readonly [ string , string , string ] | undefined {
217+ return RPC_FALLBACKS [ chainId ] ;
218+ }
219+
212220/**
213221 * Returns the appropriate polling interval (ms) for a given chain ID,
214222 * tuned to block time so we don't spam RPCs on slow chains or lag on fast ones.
You can’t perform that action at this time.
0 commit comments