How to resolve ENS name?

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

import { resolveName } from "thirdweb/extensions/ens";
const name = await resolveName({
  client,
  address: "0x1234...",
});

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 { resolveName } from "thirdweb/extensions/ens";

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

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?
😞
😐
🤩