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.
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.
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.
Optional
settings: AptosSettingsOptional configuration settings for the Aptos client.
Optional
Readonly
client?: ClientOptional
Readonly
clientConfig?: ClientConfigOptional
Readonly
faucet?: stringOptional
Readonly
faucetConfig?: FaucetConfigOptional
Readonly
fullnode?: stringOptional
Readonly
fullnodeConfig?: FullNodeConfigOptional
Readonly
indexer?: stringOptional
Readonly
indexerConfig?: IndexerConfigOptional
Readonly
network?: NetworkOptional
Readonly
pepper?: stringOptional
Readonly
prover?: stringimport { 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);
Readonly
client: ClientThe client instance the SDK uses. Defaults to `@aptos-labs/aptos-client
Optional
Readonly
clientConfig?: ClientConfigOptional client configurations
Optional
Readonly
faucet?: stringThe optional hardcoded faucet URL to send requests to instead of using the network
Optional
Readonly
faucetConfig?: FaucetConfigOptional specific Faucet configurations
Optional
Readonly
fullnode?: stringThe optional hardcoded fullnode URL to send requests to instead of using the network
Optional
Readonly
fullnodeConfig?: ClientHeadersTypeOptional specific Fullnode configurations
Optional
Readonly
indexer?: stringThe optional hardcoded indexer URL to send requests to instead of using the network
Optional
Readonly
indexerConfig?: ClientHeadersTypeOptional specific Indexer configurations
Readonly
network: NetworkThe Network that this SDK is associated with. Defaults to DEVNET
Optional
Readonly
pepper?: stringThe optional hardcoded pepper service URL to send requests to instead of using the network
Optional
Readonly
prover?: stringThe optional hardcoded prover service URL to send requests to instead of using the network
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.
The type of Aptos API to get the URL for. This can be one of the following: FULLNODE, FAUCET, INDEXER, PEPPER, PROVER.
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);
Checks if the provided URL is a known pepper service endpoint.
The URL to check against the known pepper service endpoints.
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);
Checks if the provided URL is a known prover service endpoint.
The URL to check against known prover service endpoints.
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}`);
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.
The arguments for retrieving account domains.
Arguments for retrieving the domains associated with a specific account.
Optional
options?: PaginationArgs & OrderByArg<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.
The arguments for fetching account names.
Arguments for retrieving account names based on the specified account address.
Optional
options?: PaginationArgs & OrderByArg<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.
The arguments for retrieving subdomains.
Arguments for retrieving subdomains associated with a specific account.
Optional
options?: PaginationArgs & OrderByArg<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.
The arguments for fetching subdomains.
Arguments for retrieving subdomains associated with a specific domain.
Optional
options?: PaginationArgs & OrderByArg<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.
The arguments for retrieving the expiration.
A string of the name to retrieve.
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.
The arguments for retrieving the name.
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.
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.
The arguments for retrieving the owner address.
A string representing the name of the domain or subdomain to retrieve the owner address for.
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.
The arguments for retrieving the primary name.
An AccountAddressInput (address) of the account.
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.
The arguments for retrieving the target address.
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").
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.
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.
The arguments for renewing the domain.
A string representing the domain to renew. Subdomains cannot be renewed.
Optional
options?: InputGenerateTransactionOptionsOptional transaction options.
The sender account, which must be the domain owner.
Optional
years?: 1The number of years to renew the name. Currently, only one year is permitted.
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.
The arguments for setting the primary name.
Optional
name?: stringA string representing the name to set as primary (e.g., "test.aptos").
Optional
options?: InputGenerateTransactionOptionsOptional transaction options.
The sender account.
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.
The arguments for setting the target address.
The AccountAddressInput of the address to set the domain or subdomain to.
A string representing the domain or subdomain name (e.g., "test.aptos").
Optional
options?: InputGenerateTransactionOptionsOptional settings for generating the transaction.
The account initiating the transaction.
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);
A class to handle all
ANS
operations.