Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions lib/rpc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { createPublicClient, http, fallback } from "viem";
import { base, baseSepolia } from "viem/chains";

const chainId = Number(process.env.NEXT_PUBLIC_CHAIN_ID || "84532");
const chain = chainId === 8453 ? base : baseSepolia;

const customRpc = process.env.NEXT_PUBLIC_RPC_URL;

const transport = customRpc
? fallback([http(customRpc), http()])
: http();

/**
* Shared public client for reading from Base (or Base Sepolia).
*
* Chain is selected via NEXT_PUBLIC_CHAIN_ID (default: 84532 / Base Sepolia).
* Uses NEXT_PUBLIC_RPC_URL with a fallback to the chain's default public RPC.
*/
export const publicClient = createPublicClient({
chain,
transport,
});
15 changes: 3 additions & 12 deletions lib/viem.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
import { createPublicClient, http } from "viem";
import { base } from "viem/chains";

/**
* Public client for reading from Base.
*
* Uses the default Base RPC. Override via BASE_RPC_URL env var.
*/
export const publicClient = createPublicClient({
chain: base,
transport: http(process.env.BASE_RPC_URL || undefined),
});
// Re-export from lib/rpc.ts — this file exists for backward compatibility.
// New code should import from "lib/rpc" directly.
export { publicClient } from "./rpc";
Loading