A class to handle all ANS operations.

Hierarchy (View Summary)

ANS

  • Initializes a new instance of the Aptos class with the provided configuration. This allows you to interact with the Aptos blockchain using the specified network settings.

    Parameters

    • config: AptosConfig

      The configuration settings for the Aptos client.

      Represents the configuration settings for an Aptos SDK client instance. This class allows customization of various endpoints and client settings.

      • constructor:function
        • Initializes an instance of the Aptos client with the specified settings. This allows users to configure various aspects of the client, such as network and endpoints.

          Parameters

          • Optionalsettings: AptosSettings

            Optional configuration settings for the Aptos client.

            • Optional Readonlyclient?: Client
            • Optional ReadonlyclientConfig?: ClientConfig
            • Optional Readonlyfaucet?: string
            • Optional ReadonlyfaucetConfig?: FaucetConfig
            • Optional Readonlyfullnode?: string
            • Optional ReadonlyfullnodeConfig?: FullNodeConfig
            • Optional Readonlyindexer?: string
            • Optional ReadonlyindexerConfig?: IndexerConfig
            • Optional Readonlynetwork?: Network
            • Optional Readonlypepper?: string
            • Optional Readonlyprover?: string

          Returns AptosConfig

          import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";

          async function runExample() {
          // Create a new Aptos client with default settings
          const config = new AptosConfig({ network: Network.TESTNET }); // Specify the network
          const aptos = new Aptos(config);

          console.log("Aptos client initialized:", aptos);
          }
          runExample().catch(console.error);
      • Readonlyclient: Client

        The client instance the SDK uses. Defaults to `@aptos-labs/aptos-client

      • Optional ReadonlyclientConfig?: ClientConfig

        Optional client configurations

      • Optional Readonlyfaucet?: string

        The optional hardcoded faucet URL to send requests to instead of using the network

      • Optional ReadonlyfaucetConfig?: FaucetConfig

        Optional specific Faucet configurations

      • Optional Readonlyfullnode?: string

        The optional hardcoded fullnode URL to send requests to instead of using the network

      • Optional ReadonlyfullnodeConfig?: ClientHeadersType

        Optional specific Fullnode configurations

      • Optional Readonlyindexer?: string

        The optional hardcoded indexer URL to send requests to instead of using the network

      • Optional ReadonlyindexerConfig?: ClientHeadersType

        Optional specific Indexer configurations

      • Readonlynetwork: Network

        The Network that this SDK is associated with. Defaults to DEVNET

      • Optional Readonlypepper?: string

        The optional hardcoded pepper service URL to send requests to instead of using the network

      • Optional Readonlyprover?: string

        The optional hardcoded prover service URL to send requests to instead of using the network

      • getRequestUrl:function
        • Returns the URL endpoint to send the request to based on the specified API type. If a custom URL was provided in the configuration, that URL is returned. Otherwise, the URL endpoint is derived from the network.

          Parameters

          • apiType: AptosApiType

            The type of Aptos API to get the URL for. This can be one of the following: FULLNODE, FAUCET, INDEXER, PEPPER, PROVER.

          Returns string

          import { Aptos, AptosConfig, Network, AptosApiType } from "@aptos-labs/ts-sdk";

          const config = new AptosConfig({ network: Network.TESTNET });
          const aptos = new Aptos(config);

          async function runExample() {
          // Getting the request URL for the FULLNODE API
          const url = config.getRequestUrl(AptosApiType.FULLNODE);
          console.log("Request URL for FULLNODE:", url);
          }
          runExample().catch(console.error);
      • isPepperServiceRequest:function
        • Checks if the provided URL is a known pepper service endpoint.

          Parameters

          • url: string

            The URL to check against the known pepper service endpoints.

          Returns boolean

          import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";

          const config = new AptosConfig({ network: Network.TESTNET });
          const aptos = new Aptos(config);

          async function runExample() {
          const url = "https://example.pepper.service"; // replace with a real pepper service URL

          // Check if the URL is a known pepper service endpoint
          const isPepperService = config.isPepperServiceRequest(url);

          console.log(`Is the URL a known pepper service? ${isPepperService}`);
          }
          runExample().catch(console.error);
      • isProverServiceRequest:function
        • Checks if the provided URL is a known prover service endpoint.

          Parameters

          • url: string

            The URL to check against known prover service endpoints.

          Returns boolean

          A boolean indicating whether the URL is a known prover service endpoint.

          import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";

          const config = new AptosConfig({ network: Network.TESTNET });
          const aptos = new Aptos(config);

          // Check if the URL is a known prover service endpoint
          const url = "https://prover.testnet.aptos.dev"; // replace with a real URL if needed
          const isProver = config.isProverServiceRequest(url);

          console.log(`Is the URL a known prover service? ${isProver}`);

    Returns ANS

    import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";

    async function runExample() {
    // Create a configuration for connecting to the Aptos testnet
    const config = new AptosConfig({ network: Network.TESTNET });

    // Initialize the Aptos client with the configuration
    const aptos = new Aptos(config);

    console.log("Aptos client initialized:", aptos);
    }
    runExample().catch(console.error);
  • Fetches all top-level domain names for a specified account.

    Parameters

    • args: GetAccountDomainsArgs

      The arguments for retrieving account domains.

      Arguments for retrieving the domains associated with a specific account.

      • accountAddress: AccountAddressInput
      • Optionaloptions?: PaginationArgs & OrderByArg<
            {
                domain?: null
                | string;
                domain_expiration_timestamp?: any;
                expiration_timestamp?: any;
                is_primary?: null | boolean;
                owner_address?: null | string;
                registered_address?: null | string;
                subdomain?: null | string;
                subdomain_expiration_policy?: any;
                token_standard?: null | string;
            },
        > & WhereArg<CurrentAptosNamesBoolExp>

    Returns Promise<
        {
            domain?: null
            | string;
            domain_expiration_timestamp?: any;
            expiration_timestamp?: any;
            is_primary?: null | boolean;
            owner_address?: null | string;
            registered_address?: null | string;
            subdomain?: null | string;
            subdomain_expiration_policy?: any;
            token_standard?: null | string;
        }[],
    >

    A promise of an array of ANSName.

    import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";

    const config = new AptosConfig({ network: Network.TESTNET });
    const aptos = new Aptos(config);

    async function runExample() {
    // Fetching all top-level domain names for a specific account
    const domains = await aptos.getAccountDomains({
    accountAddress: "0x1", // replace with a real account address
    options: {
    limit: 10, // specify the number of names to fetch
    offset: 0, // specify the offset for pagination
    orderBy: "created_at", // specify the order by which to sort the names
    where: {
    // additional filters can be specified here
    },
    },
    });

    console.log(domains);
    }
    runExample().catch(console.error);
  • Fetches all names for an account, including both top-level domains and subdomains.

    Parameters

    • args: GetAccountNamesArgs

      The arguments for fetching account names.

      Arguments for retrieving account names based on the specified account address.

      • accountAddress: AccountAddressInput
      • Optionaloptions?: PaginationArgs & OrderByArg<
            {
                domain?: null
                | string;
                domain_expiration_timestamp?: any;
                expiration_timestamp?: any;
                is_primary?: null | boolean;
                owner_address?: null | string;
                registered_address?: null | string;
                subdomain?: null | string;
                subdomain_expiration_policy?: any;
                token_standard?: null | string;
            },
        > & WhereArg<CurrentAptosNamesBoolExp>

    Returns Promise<
        {
            domain?: null
            | string;
            domain_expiration_timestamp?: any;
            expiration_timestamp?: any;
            is_primary?: null | boolean;
            owner_address?: null | string;
            registered_address?: null | string;
            subdomain?: null | string;
            subdomain_expiration_policy?: any;
            token_standard?: null | string;
        }[],
    >

    A promise of an array of ANSName.

    import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";

    const config = new AptosConfig({ network: Network.TESTNET });
    const aptos = new Aptos(config);

    async function runExample() {
    // Fetch account names for a specific address
    const accountNames = await aptos.getAccountNames({
    accountAddress: "0x1", // replace with a real account address
    options: {
    limit: 10, // specify how many names to fetch
    orderBy: "name", // specify the order by which to sort the names
    },
    });

    console.log(accountNames);
    }
    runExample().catch(console.error);
  • Fetches all subdomain names for a specified account.

    Parameters

    • args: GetAccountSubdomainsArgs

      The arguments for retrieving subdomains.

      Arguments for retrieving subdomains associated with a specific account.

      • accountAddress: AccountAddressInput
      • Optionaloptions?: PaginationArgs & OrderByArg<
            {
                domain?: null
                | string;
                domain_expiration_timestamp?: any;
                expiration_timestamp?: any;
                is_primary?: null | boolean;
                owner_address?: null | string;
                registered_address?: null | string;
                subdomain?: null | string;
                subdomain_expiration_policy?: any;
                token_standard?: null | string;
            },
        > & WhereArg<CurrentAptosNamesBoolExp>

    Returns Promise<
        {
            domain?: null
            | string;
            domain_expiration_timestamp?: any;
            expiration_timestamp?: any;
            is_primary?: null | boolean;
            owner_address?: null | string;
            registered_address?: null | string;
            subdomain?: null | string;
            subdomain_expiration_policy?: any;
            token_standard?: null | string;
        }[],
    >

    A promise of an array of ANSName.

    import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";

    const config = new AptosConfig({ network: Network.TESTNET });
    const aptos = new Aptos(config);

    async function runExample() {
    // Fetching subdomain names for a specific account
    const subdomains = await aptos.getAccountSubdomains({
    accountAddress: "0x1", // replace with a real account address
    options: {
    limit: 10, // specify the number of subdomains to fetch
    offset: 0, // specify the offset for pagination
    orderBy: "name", // specify the order by which to sort the names
    },
    });

    console.log(subdomains);
    }
    runExample().catch(console.error);
  • Fetches all subdomain names for a given domain, excluding the domain itself.

    Parameters

    • args: GetDomainSubdomainsArgs

      The arguments for fetching subdomains.

      Arguments for retrieving subdomains associated with a specific domain.

      • domain: string
      • Optionaloptions?: PaginationArgs & OrderByArg<
            {
                domain?: null
                | string;
                domain_expiration_timestamp?: any;
                expiration_timestamp?: any;
                is_primary?: null | boolean;
                owner_address?: null | string;
                registered_address?: null | string;
                subdomain?: null | string;
                subdomain_expiration_policy?: any;
                token_standard?: null | string;
            },
        > & WhereArg<CurrentAptosNamesBoolExp>

    Returns Promise<
        {
            domain?: null
            | string;
            domain_expiration_timestamp?: any;
            expiration_timestamp?: any;
            is_primary?: null | boolean;
            owner_address?: null | string;
            registered_address?: null | string;
            subdomain?: null | string;
            subdomain_expiration_policy?: any;
            token_standard?: null | string;
        }[],
    >

    A promise that resolves to an array of ANSName.

    import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";

    const config = new AptosConfig({ network: Network.TESTNET });
    const aptos = new Aptos(config);

    async function runExample() {
    // Fetching subdomains for a specific domain
    const subdomains = await aptos.getDomainSubdomains({
    domain: "test", // replace with your domain
    options: {
    limit: 10, // specify the number of subdomains to fetch
    offset: 0, // specify the starting point for fetching
    orderBy: "name", // specify the order by which to sort the results
    },
    });

    console.log(subdomains);
    }
    runExample().catch(console.error);
  • Retrieve the expiration time of a domain name or subdomain name from the contract.

    Parameters

    • args: { name: string }

      The arguments for retrieving the expiration.

      • name: string

        A string of the name to retrieve.

    Returns Promise<undefined | number>

    number as a unix timestamp in milliseconds.

    import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";

    const config = new AptosConfig({ network: Network.TESTNET });
    const aptos = new Aptos(config);

    async function runExample() {
    // Get the expiration time for the domain "test.aptos"
    const exp = await aptos.getExpiration({ name: "test.aptos" });

    // Log the expiration date
    console.log(new Date(exp)); // Outputs the expiration date
    }
    runExample().catch(console.error);
  • Fetches a single name from the indexer based on the provided name argument.

    Parameters

    • args: { name: string }

      The arguments for retrieving the name.

      • name: string

        A string of the name to retrieve, e.g. "test.aptos.apt" or "test.apt" or "test". Can be inclusive or exclusive of the .apt suffix and can be a subdomain.

    Returns Promise<
        | undefined
        | {
            domain?: null
            | string;
            domain_expiration_timestamp?: any;
            expiration_timestamp?: any;
            is_primary?: null | boolean;
            owner_address?: null | string;
            registered_address?: null | string;
            subdomain?: null | string;
            subdomain_expiration_policy?: any;
            token_standard?: null | string;
        },
    >

    A promise of an ANSName or undefined if the name is not active.

    import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";

    const config = new AptosConfig({ network: Network.TESTNET });
    const aptos = new Aptos(config);

    async function runExample() {
    // Fetching a name from the indexer
    const name = await aptos.getName({ name: "test.aptos" }); // replace with a real name
    console.log(name);
    }
    runExample().catch(console.error);
  • Retrieve the owner address of a specified domain name or subdomain name from the contract.

    Parameters

    • args: { name: string }

      The arguments for retrieving the owner address.

      • name: string

        A string representing the name of the domain or subdomain to retrieve the owner address for.

    Returns Promise<undefined | AccountAddress>

    AccountAddress if the name is owned, undefined otherwise.

    import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";

    const config = new AptosConfig({ network: Network.TESTNET });
    const aptos = new Aptos(config);

    async function runExample() {
    // Retrieve the owner address of "test.aptos"
    const owner = await aptos.getOwnerAddress({ name: "test.aptos" });
    console.log(owner); // Logs the owner address or undefined if not owned
    }
    runExample().catch(console.error);
  • Retrieve the primary name for an account. An account can have multiple names, but only one primary name, which may not exist.

    Parameters

    Returns Promise<undefined | string>

    A string if the account has a primary name, undefined otherwise.

    import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";

    const config = new AptosConfig({ network: Network.TESTNET });
    const aptos = new Aptos(config);

    async function runExample() {
    // Retrieve the primary name for the specified account address
    const name = await aptos.getPrimaryName({ address: "0x1" }); // replace with a real account address
    console.log(name);
    }
    runExample().catch(console.error);
  • Retrieve the target address of a domain or subdomain name, which indicates the address the name points to for use on-chain. Note that the target address can point to addresses that do not own the name.

    Parameters

    • args: { name: string }

      The arguments for retrieving the target address.

      • name: string

        A string representing the name, which can be a primary name, a subdomain, or a combination (e.g., "primary", "primary.apt", "secondary.primary", "secondary.primary.apt").

    Returns Promise<undefined | AccountAddress>

    AccountAddress if the name has a target, undefined otherwise.

    import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";

    const config = new AptosConfig({ network: Network.TESTNET });
    const aptos = new Aptos(config);

    async function runExample() {
    // Retrieve the target address for the specified domain name
    const targetAddr = await aptos.getTargetAddress({ name: "test.aptos" });

    console.log(targetAddr); // Logs the target address, e.g., 0x123...
    }
    runExample().catch(console.error);
  • Registers a new name.

    This function allows you to register a domain or subdomain name with specific expiration policies and options.

    Parameters

    Returns Promise<SimpleTransaction>

    SimpleTransaction

    import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";

    const config = new AptosConfig({ network: Network.TESTNET });
    const aptos = new Aptos(config);

    async function runExample() {
    // Registering a subdomain name assuming def.apt is already registered and belongs to the sender alice.
    const txn = await aptos.registerName({
    sender: "0x1", // replace with a real sender account
    name: "test.aptos.apt",
    expiration: {
    policy: "subdomain:independent",
    expirationDate: Date.now() + 30 * 24 * 60 * 60 * 1000, // expires in 30 days
    },
    });

    console.log("Transaction:", txn);
    }
    runExample().catch(console.error);
  • Renews a domain name for one year. If a domain name was minted with V1 of the contract, it will automatically be upgraded to V2 via this transaction.

    Parameters

    • args: {
          name: string;
          options?: InputGenerateTransactionOptions;
          sender: Account;
          years?: 1;
      }

      The arguments for renewing the domain.

      • name: string

        A string representing the domain to renew. Subdomains cannot be renewed.

      • Optionaloptions?: InputGenerateTransactionOptions

        Optional transaction options.

      • sender: Account

        The sender account, which must be the domain owner.

      • Optionalyears?: 1

        The number of years to renew the name. Currently, only one year is permitted.

    Returns Promise<SimpleTransaction>

    SimpleTransaction

    import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";

    const config = new AptosConfig({ network: Network.TESTNET });
    const aptos = new Aptos(config);

    async function runExample() {
    // Renew the domain "test" for one year
    const transaction = await aptos.renewDomain({
    sender: Account.generate(), // replace with a real account
    name: "test"
    });

    console.log(transaction);
    }
    runExample().catch(console.error);
  • Sets the primary name for the sender account, allowing them to designate a single primary name among potentially multiple names. An account may not have a primary name.

    Parameters

    Returns Promise<SimpleTransaction>

    SimpleTransaction

    import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";

    const config = new AptosConfig({ network: Network.TESTNET });
    const aptos = new Aptos(config);

    async function runExample() {
    // Set the primary name for the sender account
    const sender = Account.generate(); // replace with a real account
    await aptos.setPrimaryName({ sender, name: "test.aptos" });

    const primaryName = await aptos.getPrimaryName({ address: sender.accountAddress });
    console.log("Primary Name:", primaryName); // Should log: "Primary Name: test.aptos"
    }
    runExample().catch(console.error);
  • Sets the target address of a domain or subdomain name, pointing it to a specified address for use on-chain. The target address can be different from the owner of the name.

    Parameters

    Returns Promise<SimpleTransaction>

    SimpleTransaction

    import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";

    const config = new AptosConfig({ network: Network.TESTNET });
    const aptos = new Aptos(config);

    async function runExample() {
    // Setting the target address for a domain name
    const sender = Account.generate(); // replace with a real account
    const address = "0x1"; // replace with a real account address

    await aptos.setTargetAddress({
    sender: sender,
    name: "test.aptos",
    address: address,
    });

    const targetAddress = await aptos.getTargetAddress({ name: "test.aptos" });
    console.log(targetAddress); // Should log the address set for "test.aptos"
    }
    runExample().catch(console.error);

Properties

config: AptosConfig

The configuration settings for the Aptos client.

MMNEPVFCICPMFPCPTTAAATR