Skip to content

Conversation

@cpcramer
Copy link

@cpcramer cpcramer commented Apr 11, 2025

What changed? Why?
Added new multicall ENS resolution utilities with useAddresses hook and getAddresses utility function to efficiently resolve multiple ENS or Basenames to Ethereum addresses, reducing network requests and improving performance for batch resolution scenarios.

Notes to reviewers

Follow up from chore: Add bidirectional resolution validation when batching Basenames and ENS names. As an additional fast follow, I will be implementing this function into getNames.

How has it been tested?
Unit tests.

@vercel
Copy link

vercel bot commented Apr 11, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
onchainkit-coverage ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 11, 2025 9:40pm
onchainkit-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 11, 2025 9:40pm
onchainkit-routes ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 11, 2025 9:40pm

@cpcramer cpcramer changed the title feat: Add multicall support for ENS / Basenames forward resolution feat: Add batching support for fetching Ethereum addresses from ENS or Basenames Apr 11, 2025
@cpcramer cpcramer changed the title feat: Add batching support for fetching Ethereum addresses from ENS or Basenames feat: Add batch ENS / Basename resolution with useAddresses hook and getAddresses utility Apr 11, 2025
queryKey,
queryFn: () => getAddresses({ names, chain }),
enabled: !!names.length,
...DEFAULT_QUERY_OPTIONS,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I'd recommend always putting defaults at the top of the object, otherwise if someone adds a default that conflicts with the keys above (unlikely in this case), things won't work as expected.

E.g. if someone added enabled: true to the default options, it'll take precedence over enabled: !!names.length

const queryKey = ['useAddresses', namesKey, chain.id];

return useQuery<GetAddressReturnType[]>({
queryKey,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion(non-blocking): 100% personal preference, but if you wanna save some variable declaraions...

queryKey: ['useAddresses', ...names, chain.id],

// Filter out null or undefined names
const validItems = names
.map((name, index) => (name ? { name, index } : null))
.filter((item): item is { name: string; index: number } => item !== null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion(non-blocking): Filtering before mapping lets you skip some operations. Super trivial in terms of perf gains in this case, but in some cases it can be meaningful

Copy link
Contributor

@dgca dgca Apr 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nvm, I see why this is the way it is. The user can pass "" as a name and you wanna preserve index order.

In that case, you could go with something like this if you wanna be more succinct (this would replace lines 32-73)

  const addressPromises = names.map(async (name) => {
    if (!name) return null;

    try {
      const address = await client.getEnsAddress({
        name,
        universalResolverAddress: isBasename(name)
          ? RESOLVER_ADDRESSES_BY_CHAIN_ID[chain.id]
          : undefined,
      });
      return address;
    } catch (error) {
      console.error(`Error resolving address for ${name}:`, error);
      return null;
    }
  });

  try {
    return await Promise.all(addressPromises);
  } catch (err) {
    console.error('Error resolving addresses in batch:', err);
    return Array(names.length).fill(null);
  }

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Saw this after merging, will look at refactoring!

@brendan-defi
Copy link
Contributor

nice, love this

@cpcramer cpcramer merged commit 7eb0e94 into main Apr 14, 2025
14 checks passed
@cpcramer cpcramer deleted the paul/add-batching-ens-to-address branch April 14, 2025 16:21
Dargon789 pushed a commit to Dargon789/onchainkit that referenced this pull request May 26, 2025
Dargon789 added a commit to Dargon789/onchainkit that referenced this pull request Dec 15, 2025
* Add .circleci/config.yml

* chore: add context exports (coinbase#2261)

* feat: Add batch ENS / Basename resolution with useAddresses hook and getAddresses utility (coinbase#2277)

* chore: add provider exports back (coinbase#2278)

* refactor: Replace Packemon with Vite (coinbase#2227)

* fix: Don't clean out out dir when building in dev mode (coinbase#2279)

* fix wallet modal (coinbase#2282)

* fix: Separate deafult Wagmi and Query providers (coinbase#2280)

* chore: show connect button when disconnected in Identity demo (coinbase#2285)

* Fix: Flaky AppchainBridgeProvider network toggle test (coinbase#2288)

* refactor: send display name (coinbase#2283)

* chore: Refactor getNames utility to leverage batch processing with getAddresses (coinbase#2281)

* chore: fix typos in documentation (coinbase#2286)

* chore: Dynamically set version in version.ts (coinbase#2290)

* fix: viem version (coinbase#2291)

* fix: viem (coinbase#2293)

* fix: viem (coinbase#2295)

* chore: Add @farcaster/frame-sdk dependency to minikit templates (coinbase#2297)

* chore: bump cli templates deps (coinbase#2296)

* chore: remove smart wallet check from cli prompt (coinbase#2287)

* fix: ready options (coinbase#2300)

* fix: authenticate against user fid (coinbase#2299)

* chore: version packages v 0.38.8 🌊 (coinbase#2276)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Dan Cortes <3639170+dgca@users.noreply.github.com>

* fix: OnchainKit package.json publishConfig.access = public (coinbase#2306)

* chore: add redirect for `getOnrampBuyUrl` (coinbase#2104)

* fix: signature provider unmount reset (coinbase#2172)

* fix: Updates playground to remove outdated imports (coinbase#2294)

* chore(deps): bump next from 14.2.25 to 14.2.26 (coinbase#2215)

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore: update `create-onchain` version (coinbase#2315)

* fix: rpcUrl (coinbase#2319)

* chore: update release workflows (coinbase#2314)

* fix: fix root build command (coinbase#2320)

* fix: fix build command in workflow (coinbase#2321)

* fix: narrow filtering for release workflow (coinbase#2322)

* chore: version packages  v0.38.9 🌊 (coinbase#2323)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Alissa Crane <alissacranespam@gmail.com>

* fix: support an insecure fallback for session id to allow for testing on http contexts (coinbase#2318)

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>

* chore: Make create-onchain library public (coinbase#2324)

* chore: Don't ask to generate manifest during app creation in create-onchain (coinbase#2326)

* fix: Basenames bidirectional validation (coinbase#2329)

* chore: version packages v0.38.10 🌊 (coinbase#2330)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Alissa Crane <alissacranespam@gmail.com>

* fix: getSocials (coinbase#2333)

* docs: fix broken link (coinbase#2331)

* feat: Make sign up button optional (coinbase#2332)

* chore: Release changesets (coinbase#2342)

* Chore: workflow improvement for vscode/cursor users (coinbase#2334)

* chore: version packages 🚀 (coinbase#2343)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Dan Cortes <3639170+dgca@users.noreply.github.com>

* chore: enable paymaster for wallet advanced Send (coinbase#2335)

* fix: MiniKit frames connector (coinbase#2347)

* chore: version packages 🚀 (coinbase#2348)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Dan Cortes <3639170+dgca@users.noreply.github.com>

* fix: Update wagmi config if connectors change (coinbase#2350)

* chore: version packages 🚀 (coinbase#2352)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Dan Cortes <3639170+dgca@users.noreply.github.com>

* chore(deps-dev): bump vite from 6.2.3 to 6.2.7 (coinbase#2327)

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore: Use signed commits for Changesets action (coinbase#2351)

* chore: Update MiniKit mini app manifest (coinbase#2355)

* chore: version packages 🚀 (coinbase#2362)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Dan Cortes <3639170+dgca@users.noreply.github.com>

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Alissa Crane <alissacranespam@gmail.com>
Co-authored-by: Paul Cramer <paulccramer@gmail.com>
Co-authored-by: Dan Cortes <3639170+dgca@users.noreply.github.com>
Co-authored-by: Brendan from DeFi <brendan.forster@coinbase.com>
Co-authored-by: leopardracer <136604165+leopardracer@users.noreply.github.com>
Co-authored-by: Adam <alessey@gmail.com>
Co-authored-by: Zach Blake <ztb@pm.me>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Daniel Schlabach <31226559+dschlabach@users.noreply.github.com>
Co-authored-by: Teimur Gasanov <teymurgg321@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: xtbase <teaonbase@gmail.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: GarmashAlex <garmasholeksii@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants