Aptos Names

K
Account

This documentation is using @aptos-labs/ts-sdk v6.0.0

Basic Usage

This guide covers the basics of using the Aptos Name Service via the TS SDK. Learn how to fetch names and work with the TS SDK.

Basic Example

Fetch a name by its domain:

export async function fetchName() {
  const aptos = new Aptos(new AptosConfig({ network: Network.MAINNET }));

  // Fetch a name by domain (e.g., "example.apt")
  const name = await aptos.getName({
    name: "example.apt",
  });

  if (name) {
    console.log("Name found:", name);
    console.log("Owner:", name.owner_address);
    console.log("Expiration:", name.expiration);
  } else {
    console.log("Name not found or unclaimed");
  }

  return name;
}

With Subdomain

Fetch a name with a subdomain:

export async function fetchNameWithSubdomain() {
  const aptos = new Aptos(new AptosConfig({ network: Network.MAINNET }));

  // Fetch a subdomain name (e.g., "subdomain.example.apt")
  const name = await aptos.getName({
    name: "subdomain.example.apt",
  });

  if (name) {
    console.log("Subdomain found:", name);
    console.log("Domain:", name.domain);
    console.log("Subdomain:", name.subdomain);
    console.log("Owner:", name.owner_address);
  } else {
    console.log("Subdomain not found or unclaimed");
  }

  return name;
}