Skip to content

fix: add multicall batching to viem client#2254

Merged
sevenzing merged 3 commits into
mainfrom
ll/fixing-batch-multicall
Jun 5, 2026
Merged

fix: add multicall batching to viem client#2254
sevenzing merged 3 commits into
mainfrom
ll/fixing-batch-multicall

Conversation

@sevenzing
Copy link
Copy Markdown
Member

@sevenzing sevenzing commented Jun 4, 2026

closes #2237

Summary

Enabling multicall batchin in viem: https://viem.sh/docs/clients/public#batchmulticall-optional

Why

Viem doesnt support eth_call batching by default!


Testing

  • How this was tested.
  • If you didn't test it, say why.

Notes for Reviewer (Optional)

  • Anything non-obvious or worth a heads-up.

Pre-Review Checklist (Blocking)

  • This PR does not introduce significant changes and is low-risk to review quickly.
  • Relevant changesets are included (or are not required)

@sevenzing sevenzing requested a review from a team as a code owner June 4, 2026 09:35
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jun 4, 2026

⚠️ No Changeset found

Latest commit: eb82213

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Jun 4, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
enskit-react-example.ensnode.io Ready Ready Preview, Comment Jun 5, 2026 12:25pm
3 Skipped Deployments
Project Deployment Actions Updated (UTC)
admin.ensnode.io Skipped Skipped Jun 5, 2026 12:25pm
ensnode.io Skipped Skipped Jun 5, 2026 12:25pm
ensrainbow.io Skipped Skipped Jun 5, 2026 12:25pm

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 4, 2026

Review Change Stack

Warning

Review limit reached

@sevenzing, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 52 minutes and 25 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7970e180-f76b-4ce7-a799-fc45915f5ddc

📥 Commits

Reviewing files that changed from the base of the PR and between 10c2583 and eb82213.

📒 Files selected for processing (2)
  • apps/ensapi/src/di.ts
  • apps/ensapi/src/lib/public-client.ts
📝 Walkthrough

Walkthrough

A new utility module buildPublicClient encapsulates public client creation with configured multicall batch size and fallback HTTP transports. The DI setup is refactored to use this shared builder instead of constructing the client inline, reducing duplication and improving maintainability.

Changes

Public client builder extraction and DI integration

Layer / File(s) Summary
Public client builder utility
apps/ensapi/src/lib/public-client.ts
New buildPublicClient function creates a viem PublicClient for the ENS root chain with multicall batch size 2048 and a fallback HTTP transport from provided RPC URLs.
DI integration of public client builder
apps/ensapi/src/di.ts
The rootChainPublicClient getter calls buildPublicClient instead of constructing the client inline. viem imports simplified to type-only PublicClient, and a new import for buildPublicClient is added.

🎯 2 (Simple) | ⏱️ ~10 minutes

🐰 A client builder hops into the warren,
No more inline magic in the DI chain—
Shared and reusable, clean and bright,
The public client finds its rightful home,
Where configurations bloom in autumn light. 🌙

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The PR description is largely incomplete. Critical sections like Testing and Notes for Reviewer contain only placeholder text, and the Pre-Review Checklist items are left unchecked despite being marked as blocking. Complete the Testing section with concrete test steps or explanation of why testing was not performed. Address the blocking Pre-Review Checklist items by checking them or providing reasoning. Add any relevant notes for reviewers in the designated section.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding multicall batching to the viem client, which is the core objective of the PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ll/fixing-batch-multicall

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.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Jun 4, 2026

Greptile Summary

Enables viem multicall batching on the ENS root chain PublicClient by extracting client construction into a dedicated buildRootChainPublicClient helper. The new client also now explicitly sets the chain (via getENSRootChain(namespace)), which was missing before and is required for viem to resolve the correct multicall3 contract address.

  • public-client.ts: New helper wraps createPublicClient with batch.multicall enabled (batchSize: 2048 bytes) and a fallback transport over all configured HTTP RPCs.
  • di.ts: rootChainPublicClient getter delegates to the new helper, passing rootChainRpcConfig and namespace; unneeded viem imports are cleaned up.

Confidence Score: 5/5

Safe to merge — the change is a focused, additive configuration tweak with a clean extraction refactor.

The diff is small and self-contained: multicall batching is opt-in at the viem client level and degrades gracefully (viem falls back to individual calls if the multicall contract isn't available). The new explicit chain setting is a correctness improvement needed for viem to locate the right multicall3 contract. No logic paths are altered in di.ts beyond delegating to the new helper.

No files require special attention.

Important Files Changed

Filename Overview
apps/ensapi/src/lib/public-client.ts New helper that creates the ENS root chain PublicClient with multicall batching (batchSize 2048) and an explicit chain config derived from the namespace.
apps/ensapi/src/di.ts Refactored rootChainPublicClient getter to delegate to buildRootChainPublicClient; removes inline viem imports no longer needed here.

Sequence Diagram

sequenceDiagram
    participant DI as EnsApiDiContainer
    participant Builder as buildRootChainPublicClient
    participant Viem as viem PublicClient
    participant MC as Multicall3 Contract (on-chain)
    participant RPC as Fallback HTTP RPCs

    DI->>Builder: buildRootChainPublicClient(rootChainRpcConfig, namespace)
    Builder->>Viem: "createPublicClient({ chain, batch.multicall, transport: fallback([...]) })"
    Viem-->>DI: PublicClient instance

    note over Viem,MC: On contract reads
    DI->>Viem: readContract / call (N calls in same tick)
    Viem->>MC: aggregate3 batch (≤2048 bytes calldata)
    MC-->>RPC: single eth_call
    RPC-->>MC: aggregated results
    MC-->>Viem: decoded results[]
    Viem-->>DI: results
Loading

Reviews (4): Last reviewed commit: "rename build function" | Re-trigger Greptile

Comment thread apps/ensapi/src/lib/public-client.ts
@vercel vercel Bot temporarily deployed to Preview – admin.ensnode.io June 4, 2026 09:42 Inactive
@vercel vercel Bot temporarily deployed to Preview – ensrainbow.io June 4, 2026 09:42 Inactive
@vercel vercel Bot temporarily deployed to Preview – ensnode.io June 4, 2026 09:42 Inactive
Comment thread apps/ensapi/src/lib/public-client.ts
@sevenzing
Copy link
Copy Markdown
Member Author

@greptile review

@vercel vercel Bot temporarily deployed to Preview – ensrainbow.io June 5, 2026 12:25 Inactive
@vercel vercel Bot temporarily deployed to Preview – ensnode.io June 5, 2026 12:25 Inactive
@vercel vercel Bot temporarily deployed to Preview – admin.ensnode.io June 5, 2026 12:25 Inactive
@sevenzing sevenzing merged commit ee0feed into main Jun 5, 2026
20 checks passed
@sevenzing sevenzing deleted the ll/fixing-batch-multicall branch June 5, 2026 12:31
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.

execute-operations; refactor to use viem.multicall

2 participants