fix: use CORS-friendly public RPCs as fallbacks when no PUBLIC_RPC_* env vars are set#445
fix: use CORS-friendly public RPCs as fallbacks when no PUBLIC_RPC_* env vars are set#445gabitoesmiapodo merged 6 commits intodevelopfrom
Conversation
…env vars are set When PUBLIC_RPC_* env vars are not configured, viem falls back to chain defaults (e.g. eth.merkle.io for mainnet) which block cross-origin requests. Replace with publicnode.com fallbacks that set Access-Control-Allow-Origin: *. Closes #441
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
This PR updates the app’s viem/wagmi transport configuration so that when PUBLIC_RPC_* env vars are unset, the app uses CORS-friendly fallback RPC endpoints (publicnode.com) instead of viem’s chain-default public RPCs that can fail CORS in browsers (notably on localhost and Vercel previews).
Changes:
- Added publicnode.com fallback URLs for the currently configured chains in
transportswhenPUBLIC_RPC_*is unset. - Updated
.env.exampleRPC comment to reflect the new fallback behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/lib/networks.config.ts |
Adds publicnode.com URLs as fallbacks for the configured chain transports when env RPCs are missing. |
.env.example |
Updates the RPC section comment to describe the new default behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
@fernandomg that looks fine, but I researched a bit and:
In any case, it's something we can evaluate in a different issue / PR. This one solved what intended to solve. |
Summary
When
PUBLIC_RPC_*env vars are not configured, viem falls back to chain-built-in default RPCs (e.g.eth.merkle.iofor mainnet) which do not setAccess-Control-Allow-Originheaders. This breaks all on-chain features from any browser origin, includinglocalhostand*.vercel.apppreview deployments.Closes #441
Changes
src/lib/networks.config.ts: add CORS-friendly publicnode.com fallback URLs for all 6 configured chains via||in eachhttp()call.env.example: update RPC comment to reflect new default behaviorAcceptance criteria
PUBLIC_RPC_*env vars setpnpm devwithout RPC env varsPUBLIC_RPC_*is set, the custom URL is used (not the fallback)Test plan
pnpm lint-- passespnpm test-- 170 tests pass across 32 test filespnpm devwithout anyPUBLIC_RPC_*in.env.local, confirm no CORS errors frometh.merkle.ioChecklist