@superdevfavour/basename
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

@superdevfavour/basename

A JavaScript/TypeScript utility that simplifies interactions with Ethereum Name Service (ENS) basenames, allowing you to retrieve basename information such as avatars, text records, and more. This package provides helper methods for working with ENS .base.eth domains.

Features

  • Fetch basename for a given Ethereum address.
  • Retrieve avatars associated with ENS basenames.
  • Access various text records (e.g., description, social media handles) from ENS basenames.

Installation

Install the package using npm or yarn:

npm install @superdevfavour/basename

Or

yarn add @superdevfavour/basename

Usage

Here's how to use the package in your TypeScript or JavaScript project:

Importing the module

import {
  getBasename,
  getBasenameAvatar,
  getBasenameTextRecord,
  getBasenameTextRecords,
  BasenameTextRecordKeys,
} from "basename";

Example 1: Get a Basename from an Ethereum Address

const address: Address = "0x1234...abcd";
const basename = await getBasename(address);
console.log(basename); // Output: example.base.eth

Example 2: Get an Avatar for a Basename

const avatar = await getBasenameAvatar("example.base.eth");
console.log(avatar); // Output: Avatar URL

Example 3: Get Specific Text Records from a Basename

const description = await getBasenameTextRecord(
  "example.base.eth",
  BasenameTextRecordKeys.Description
);
console.log(description); // Output: ENS description

Example 4: Get All Text Records for a Basename

const allRecords = await getBasenameTextRecords(
  "example.base.eth",
  BasenameTextRecordKeys
);
console.log(allRecords); // Output: { description: "...", url: "...", ... }

API Reference

getBasename(address: Address): Promise<string>

Fetches the ENS basename (e.g., example.base.eth) associated with a given Ethereum address.

  • Parameters:

    • address: Ethereum address of type Address from viem.
  • Returns:

    • A Promise that resolves to a string representing the basename.

getBasenameAvatar(basename: Basename): Promise<string>

Retrieves the avatar URL for a given ENS basename.

  • Parameters:

    • basename: The ENS basename, such as example.base.eth.
  • Returns:

    • A Promise that resolves to a string containing the avatar URL.

getBasenameTextRecord(basename: string, key: BasenameTextRecordKeys): Promise<string>

Fetches a specific text record from the ENS basename.

  • Parameters:

    • basename: The ENS basename, such as example.base.eth.
    • key: A BasenameTextRecordKeys enum representing the desired text record.
  • Returns:

    • A Promise that resolves to the text record value.

getBasenameTextRecords(basename: string, key: BasenameTextRecordKeys): Promise<RecordResult[]>

Fetches all text records associated with the ENS basename.

  • Parameters:

    • basename: The ENS basename, such as example.base.eth.
    • key: An array BasenameTextRecordKeys enum to define the type of records. optional
  • Returns:

    • An Promise that resolves to an object containing all text records.

Enum: BasenameTextRecordKeys

This enum contains the keys that can be used to fetch various text records related to the basename.

  • Available Keys:
    • Description: "description"
    • Keywords: "keywords"
    • Url: "url"
    • Email: "email"
    • Phone: "phone"
    • Github: "com.github"
    • Twitter: "com.twitter"
    • Farcaster: "xyz.farcaster"
    • Lens: "xyz.lens"
    • Telegram: "org.telegram"
    • Discord: "com.discord"
    • Avatar: "avatar"

Package Sidebar

Install

npm i @superdevfavour/basename

Weekly Downloads

12

Version

1.0.6

License

ISC

Unpacked Size

29.9 kB

Total Files

9

Last publish

Collaborators

  • superdevfavour