How to resolve ENS avatar

Here is how you can resolve ENS avatar using thirdweb SDK with typescript:

import { resolveAvatar } from "thirdweb/extensions/ens";
const address = await resolveAvatar({
  client,
  name: "vitalik.eth",
});
 

Here is how you can resolve ENS name using thirdweb SDK with React:

We will create a hook for use within our React application. You can use this hook to resolve ENS names within your application:

import { client } from "@/consts/client";  // import your thirdweb client
import { queryOptions, useQuery } from "@tanstack/react-query";
import { resolveAvatar, resolveName } from "thirdweb/extensions/ens";

// Get ENS name from a wallet address
export function useGetENSAvatar({
  ensName,
}: {
  ensName: string | undefined | null;
}) {
  return useQuery(
    queryOptions({
      queryKey: ["ensAvatar", ensName || "n/a"] as const,
      queryFn: async () => {
        if (!client) {
          throw new Error("client is required");
        }
        if (!ensName) return;
        return resolveAvatar({ client, name: ensName });
      },
      enabled: !!ensName,
    })
  );
}
 

Can’t get this working? If you’ve followed the above and still have issues, contact our support team for help.

 
Did this answer your question?
😞
😐
🤩