Skip to content

fix: use configured rpc for ENS lookups#2392

Open
samsamtrum wants to merge 1 commit into
thirdweb-dev:developfrom
samsamtrum:fix-ens-custom-rpc
Open

fix: use configured rpc for ENS lookups#2392
samsamtrum wants to merge 1 commit into
thirdweb-dev:developfrom
samsamtrum:fix-ens-custom-rpc

Conversation

@samsamtrum
Copy link
Copy Markdown

@samsamtrum samsamtrum commented May 23, 2026

Summary

Fixes ENS lookups so they use the RPC URL configured for the chain instead of always falling back to viem's default transport.

Problem

getEns creates a viem public client through getProvider, but the client currently uses transport: http() without passing the configured chain.rpcUrl. For mainnet ENS resolution this can fall back to viem's default RPC endpoint, which makes custom chain RPC configuration ineffective.

Changes

  • Use chain.rpcUrl || chain.publicRpcUrl when creating the viem HTTP transport.
  • Cache viem providers by the selected RPC URL, falling back to publicRpcUrl or chain.id when no custom RPC is present.

Verification

  • npm exec --yes prettier@2.8.8 -- --check packages/core/src/provider.ts passes.
  • Static assertions confirm getProvider no longer uses bare http() and now passes the configured RPC URL.

Closes #2356

Summary by CodeRabbit

  • Refactor
    • Improved provider instance caching mechanism to more efficiently manage RPC endpoint configuration and reuse.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 23, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6e21a8ba-0aad-4dd2-a021-a7c62e4c1c33

📥 Commits

Reviewing files that changed from the base of the PR and between e3b8623 and 8e717a3.

📒 Files selected for processing (1)
  • packages/core/src/provider.ts

Walkthrough

The getProvider function is updated to cache viem PublicClient instances with improved RPC URL handling. A new getProviderCacheKey helper prioritizes chain.rpcUrl, falls back to chain.publicRpcUrl, and uses chain.id as a final fallback, ensuring clients are cached and retrieved consistently. When creating new clients, the HTTP transport is now explicitly configured with the resolved RPC URL.

Changes

Provider Caching with RPC URL Fallback

Layer / File(s) Summary
Cache key fallback and explicit HTTP transport
packages/core/src/provider.ts
New getProviderCacheKey(chain) helper computes cache keys using prioritized fallback (rpcUrl → publicRpcUrl → id). getProvider now uses this key for client instance caching and explicitly passes the resolved RPC URL to the viem HTTP transport instead of relying on default behavior.

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description provides a clear summary, problem statement, and changes made. However, the provided description template is not followed and the checklist is not completed. Complete the PR description template including the checklist items, version bump in package.json, local testing confirmation, and CI verification steps.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: using the configured RPC URL for ENS lookups instead of falling back to viem's default transport.
Linked Issues check ✅ Passed The code changes fully address issue #2356 by ensuring ENS lookups use configured RPC URLs with proper fallback logic and caching based on the selected RPC endpoint.
Out of Scope Changes check ✅ Passed All changes in provider.ts are directly scoped to fixing the ENS RPC configuration issue described in #2356, with no extraneous modifications present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

getEns doesn't pick up rpcUrl from chain configuration

1 participant