added network select feature
This commit is contained in:
@@ -10,16 +10,32 @@ const metadata = {
|
||||
};
|
||||
|
||||
// Prefer custom RPCs to avoid public-provider rate limits (429)
|
||||
const baseRpc = process.env.NEXT_PUBLIC_RPC_BASE;
|
||||
const arbitrumRpc = process.env.NEXT_PUBLIC_RPC_ARBITRUM;
|
||||
// Support runtime overrides via localStorage:
|
||||
// - rpc:base
|
||||
// - rpc:arbitrum
|
||||
// - rpc:mainnet
|
||||
function runtimeRpc(key: string): string | null {
|
||||
try {
|
||||
if (typeof window !== 'undefined' && window.localStorage) {
|
||||
const v = window.localStorage.getItem(key);
|
||||
return (v && v.trim()) ? v.trim() : null;
|
||||
}
|
||||
} catch {}
|
||||
return null;
|
||||
}
|
||||
|
||||
const enableMainnet = process.env.NEXT_PUBLIC_ENABLE_MAINNET === 'true';
|
||||
|
||||
const baseRpc = runtimeRpc('rpc:base') || process.env.NEXT_PUBLIC_RPC_BASE || 'https://base.llamarpc.com';
|
||||
const arbitrumRpc = runtimeRpc('rpc:arbitrum') || process.env.NEXT_PUBLIC_RPC_ARBITRUM || '';
|
||||
const mainnetRpc = runtimeRpc('rpc:mainnet') || '';
|
||||
|
||||
export const config = createConfig({
|
||||
chains: [base, arbitrum, ...(enableMainnet ? [mainnet] : []), sepolia],
|
||||
transports: {
|
||||
[base.id]: baseRpc ? http(baseRpc, { batch: true, retryCount: 2, retryDelay: 250 }) : http(undefined, { batch: true, retryCount: 2, retryDelay: 250 }),
|
||||
[arbitrum.id]: arbitrumRpc ? http(arbitrumRpc, { batch: true, retryCount: 2, retryDelay: 250 }) : http(undefined, { batch: true, retryCount: 2, retryDelay: 250 }),
|
||||
[mainnet.id]: http(),
|
||||
[mainnet.id]: mainnetRpc ? http(mainnetRpc, { batch: true, retryCount: 2, retryDelay: 250 }) : http(),
|
||||
[sepolia.id]: http(),
|
||||
},
|
||||
ssr: true,
|
||||
|
||||
Reference in New Issue
Block a user