From 01ce3588fffe8bfaaf033d21ceaf7dddd08a0fae Mon Sep 17 00:00:00 2001 From: Jason Schwarz Date: Mon, 26 Jan 2026 13:12:45 -0400 Subject: [PATCH 1/3] feat: add fallback transports to Wagmi config --- src/lib/wagmi.ts | 57 +++++++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/src/lib/wagmi.ts b/src/lib/wagmi.ts index 45c1c8d..4365b0f 100644 --- a/src/lib/wagmi.ts +++ b/src/lib/wagmi.ts @@ -1,3 +1,5 @@ +"use client" + import { connectorsForWallets } from "@rainbow-me/rainbowkit" import { injectedWallet, @@ -9,36 +11,24 @@ import { } from "@rainbow-me/rainbowkit/wallets" import { createConfig, http, fallback } from "wagmi" import { mainnet } from "wagmi/chains" -import { RPC_ENDPOINT } from "@/lib/network-config" -// 1. Detect environment (Safe for SSR - defaults to desktop for server render) +// 1. Environment Detection & Constants const isMobile = typeof window !== "undefined" && /Android|iPhone|iPad|iPod/i.test(navigator.userAgent) -// Get WalletConnect Project ID - required for mobile deep links -// Falls back to placeholder if not set (mobile deep links won't work, but desktop will) const projectId = process.env.NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID || "00000000000000000000000000000000" +const alchemyApiKey = process.env.NEXT_PUBLIC_ALCHEMY_API_KEY + +// 2. Connector Configuration const connectors = connectorsForWallets( [ { groupName: "Recommended", wallets: isMobile - ? [ - // MOBILE: Show specific apps to trigger Deep Links - // These wallets use WalletConnect v2 to facilitate handshake between browser and app - metaMaskWallet, - rabbyWallet, - rainbowWallet, - coinbaseWallet, - walletConnectWallet, - ] - : [ - // DESKTOP: Focus on browser extensions - // injectedWallet detects all installed extensions (MetaMask, Rabby, etc.) - injectedWallet, - ], + ? [metaMaskWallet, rabbyWallet, rainbowWallet, coinbaseWallet, walletConnectWallet] + : [injectedWallet], }, ], { @@ -47,14 +37,37 @@ const connectors = connectorsForWallets( } ) +// 3. Transport Logic (Alchemy as Default/Primary) +const rpcFallbacks = [ + // PRIMARY: Alchemy + http(`https://eth-mainnet.g.alchemy.com/v2/${alchemyApiKey}`, { + timeout: 10000, + fetchOptions: { cache: "no-store" }, + }), + + // SECONDARY: Public Nodes + http("https://eth.llamarpc.com", { timeout: 10000 }), + http("https://rpc.ankr.com/eth", { timeout: 10000 }), + http("https://1rpc.io/eth", { timeout: 10000 }), + + // LAST RESORT: Standard Public Node + http(), +] + +// 4. Final Config export const config = createConfig({ chains: [mainnet], connectors, transports: { - [mainnet.id]: fallback([ - http(RPC_ENDPOINT), // Fast RPC - http(), // public fallback - ]), + [mainnet.id]: fallback(rpcFallbacks, { + rank: true, // This will periodically test latency and pick the best one from the list + }), + }, + batch: { + multicall: { + batchSize: 1024, + wait: 20, // Bundles multiple balance checks into one RPC call + }, }, ssr: true, }) From 758ea40c000557ed1db13c06c7b05f8f39c50a5b Mon Sep 17 00:00:00 2001 From: Jason Schwarz Date: Mon, 26 Jan 2026 13:24:25 -0400 Subject: [PATCH 2/3] refactor: set backend fallback provider to Alchemy --- src/lib/network-config.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib/network-config.ts b/src/lib/network-config.ts index 366c6ee..71af17c 100644 --- a/src/lib/network-config.ts +++ b/src/lib/network-config.ts @@ -3,6 +3,8 @@ * * Network details for Ethereum Mainnet with Fast Protocol RPC */ +const alchemyApiKey = process.env.NEXT_PUBLIC_ALCHEMY_API_KEY + export const FAST_PROTOCOL_NETWORK = { chainId: 1, chainName: "Ethereum Mainnet", @@ -30,4 +32,5 @@ export const NETWORK_CONFIG = { * RPC endpoint for testing */ export const RPC_ENDPOINT = "https://fastrpc.mev-commit.xyz" -export const FALLBACK_RPC_ENDPOINT = "https://eth.llamarpc.com" +export const FALLBACK_RPC_ENDPOINT = + `https://eth-mainnet.g.alchemy.com/v2/${alchemyApiKey}` || "https://eth.llamarpc.com" From 56c90648d4eed8feb9e4c6330896007268bc321a Mon Sep 17 00:00:00 2001 From: Jason Schwarz Date: Mon, 26 Jan 2026 13:32:44 -0400 Subject: [PATCH 3/3] refactor: comment out blocked fallback rpc --- src/lib/wagmi.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/wagmi.ts b/src/lib/wagmi.ts index 4365b0f..329c4e7 100644 --- a/src/lib/wagmi.ts +++ b/src/lib/wagmi.ts @@ -46,7 +46,7 @@ const rpcFallbacks = [ }), // SECONDARY: Public Nodes - http("https://eth.llamarpc.com", { timeout: 10000 }), + // http("https://eth.llamarpc.com", { timeout: 10000 }), http("https://rpc.ankr.com/eth", { timeout: 10000 }), http("https://1rpc.io/eth", { timeout: 10000 }),