Initializes a new instance of the Aptos client with the provided configuration settings. This allows you to interact with various Aptos functionalities such as accounts, transactions, and events.
Optionalconfig: AptosConfigimport { 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 your own settings if needed
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.
Optionaloptions?: 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.
Optionaloptions?: 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.
Optionaloptions?: 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.
Optionaloptions?: 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.
Optionaloptions?: InputGenerateTransactionOptionsOptional transaction options.
The sender account, which must be the domain owner.
Optionalyears?: 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.
Optionalname?: stringA string representing the name to set as primary (e.g., "test.aptos").
Optionaloptions?: 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").
Optionaloptions?: 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);
Derives an account by providing a private key. This function resolves the provided private key type and derives the public key from it.
If the privateKey is a Secp256k1 type, it derives the account using the derived public key and auth key using the SingleKey scheme locally. If the privateKey is an ED25519 type, it looks up the authentication key on chain to determine whether it is a Legacy ED25519 key or a Unified ED25519 key, and then derives the account based on that.
The arguments for deriving the account.
OptionalminimumLedgerVersion?: AnyNumberOptionaloptions?: { throwIfNoAccountFound?: boolean }An account private key.
The derived Account type.
import { Aptos, AptosConfig, Network, Ed25519PrivateKey } from "@aptos-labs/ts-sdk";
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
async function runExample() {
// Deriving an account from a private key
const account = await aptos.deriveAccountFromPrivateKey({
privateKey: new Ed25519PrivateKey("0x123") // replace with a real private key
});
console.log(account);
}
runExample().catch(console.error);
Derives all accounts owned by a signer. This function takes a signer (either an Account or PrivateKey) and returns all accounts that can be derived from it, ordered by the most recently used account first.
Note, this function will not return accounts that require more than one signer to be used.
The arguments for deriving owned accounts
OptionalminimumLedgerVersion?: AnyNumberThe minimum ledger version to wait for before querying
Optionaloptions?: { includeUnverified?: boolean; noMultiKey?: boolean }OptionalincludeUnverified?: booleanWhether to include unverified accounts in the results. Unverified accounts are accounts that can be authenticated with the signer, but there is no history of the signer using the account. Default is false.
OptionalnoMultiKey?: booleanIf true, do not include multi-key accounts in the results. Default is false.
The signer to derive accounts from (Account or PrivateKey)
Promise resolving to an array of derived Account objects
import { Aptos, AptosConfig, Network, Ed25519Account } from "@aptos-labs/ts-sdk";
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
async function getOwnedAccounts() {
const signer = Ed25519Account.generate();
const accounts = await aptos.deriveOwnedAccountsFromSigner({
signer
});
const account = accounts[0];
console.log(account);
}
Retrieves the current amount of APT for a specified account. If the account does not exist, it will return 0.
The arguments for the account query.
The account address for which to retrieve the APT amount.
OptionalminimumLedgerVersion?: AnyNumberOptional ledger version to sync up to before querying.
The current amount of APT for the specified account.
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 APT amount for a specific account
const accountAPTAmount = await aptos.getAccountAPTAmount({ accountAddress: "0x1" }); // replace with a real account address
console.log("Account APT Amount:", accountAPTAmount);
}
runExample().catch(console.error);
Queries the current amount of a specified coin held by an account.
The parameters for querying the account's coin amount.
The account address to query for the coin amount.
OptionalcoinType?: `${string}::${string}::${string}`The coin type to query. Note: If not provided, it may be automatically populated if faMetadataAddress
is specified.
OptionalfaMetadataAddress?: AccountAddressInputThe fungible asset metadata address to query. Note: If not provided, it may be automatically
populated if coinType is specified.
OptionalminimumLedgerVersion?: AnyNumberNot used anymore, here for backward compatibility see https://github.com/aptos-labs/aptos-ts-sdk/pull/519, will be removed in the near future. Optional ledger version to sync up to before querying.
The current amount of the specified coin held by the account.
import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
async function runExample() {
// Query the account's coin amount for a specific coin type
const accountCoinAmount = await aptos.getAccountCoinAmount({
accountAddress: "0x1", // replace with a real account address
coinType: "0x1::aptos_coin::AptosCoin" // specify the coin type
});
console.log(`Account coin amount: ${accountCoinAmount}`);
}
runExample().catch(console.error);
Retrieves the current count of an account's coins aggregated across all types.
The parameters for the account coins count query.
The account address we want to get the total count for.
OptionalminimumLedgerVersion?: AnyNumberOptional ledger version to sync up to before querying.
The current count of the aggregated coins for the specified account.
import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
async function runExample() {
// Getting the account coins count for a specific account
const accountCoinsCount = await aptos.getAccountCoinsCount({ accountAddress: "0x1" }); // replace with a real account address
console.log("Account Coins Count:", accountCoinsCount);
}
runExample().catch(console.error);
Retrieves the coins data for a specified account.
The account address for which to retrieve the coin's data.
OptionalminimumLedgerVersion?: AnyNumberOptional ledger version to sync up to before querying.
Optionaloptions?: PaginationArgs & OrderByArg<An array containing the coins data for the specified account.
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 coins data for a specific account
const accountCoinsData = await aptos.getAccountCoinsData({
accountAddress: "0x1", // replace with a real account address
options: {
limit: 10, // specify the number of results to return
orderBy: { asset_type: "asc" }, // specify the order of results
},
});
console.log(accountCoinsData);
}
runExample().catch(console.error);
Queries for all collections that an account currently has tokens for, including NFTs, fungible tokens, and soulbound tokens. If you want to filter by a specific token standard, you can pass an optional tokenStandard parameter.
The account address we want to get the collections for.
OptionalminimumLedgerVersion?: AnyNumberOptional ledger version to sync up to before querying.
Optionaloptions?: TokenStandardArg & PaginationArgs & OrderByArg<Collections array with the collections data.
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 account collections with owned tokens for a specific account
const accountCollectionsWithOwnedTokens = await aptos.getAccountCollectionsWithOwnedTokens({
accountAddress: "0x1", // replace with a real account address
options: {
tokenStandard: "NFT", // specify the token standard if needed
limit: 10, // specify the number of results to return
},
});
console.log(accountCollectionsWithOwnedTokens);
}
runExample().catch(console.error);
Queries the current state for an Aptos account given its account address.
The arguments for retrieving account information.
The Aptos account address to query.
The account data.
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 account information for a specific address
const accountInfo = await aptos.getAccountInfo({ accountAddress: "0x1" }); // replace with a real account address
console.log(accountInfo);
}
runExample().catch(console.error);
Queries for a specific account module given an account address and module name.
The Aptos account address.
The name of the module.
Optionaloptions?: LedgerVersionArgThe account module associated with the specified account address and module name.
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 account module for a specific account address and module name
const module = await aptos.getAccountModule({
accountAddress: "0x1", // replace with a real account address
moduleName: "MyModule" // specify the module name
});
console.log(module);
}
runExample().catch(console.error);
Queries for all modules in an account given an account address. This function may call the API multiple times to auto paginate through results.
The Aptos account address to query modules for.
Optionaloptions?: { limit?: number } & LedgerVersionArgimport { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
async function runExample() {
// Fetching account modules for a specific account
const accountModules = await aptos.getAccountModules({
accountAddress: "0x1", // replace with a real account address
options: {
limit: 10, // limiting to 10 modules
},
});
console.log(accountModules);
}
runExample().catch(console.error);
Queries for a page of modules in an account given an account address.
The Aptos account address to query modules for.
Optionaloptions?: CursorPaginationArgs & LedgerVersionArgimport { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
async function runExample() {
// Fetching account modules for a specific account
const {modules, cursor} = await aptos.getAccountModulesPage({
accountAddress: "0x1", // replace with a real account address
options: {
cursor: undefined, // starting from the first module
limit: 10, // limiting to 10 modules
},
});
console.log(modules);
console.log(`More to fetch: ${cursor !== undefined}`);
}
runExample().catch(console.error);
Queries an account's owned objects.
The account address we want to get the objects for.
OptionalminimumLedgerVersion?: AnyNumberOptional ledger version to sync up to before querying.
Optionaloptions?: PaginationArgs & OrderByArg<Objects array with the object data.
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 objects owned by the specified account
const accountOwnedObjects = await aptos.getAccountOwnedObjects({
accountAddress: "0x1", // replace with a real account address
minimumLedgerVersion: 1, // optional, specify if needed
options: {
offset: 0, // optional, specify if needed
limit: 10, // optional, specify if needed
orderBy: "created_at", // optional, specify if needed
},
});
console.log(accountOwnedObjects);
}
runExample().catch(console.error);
Queries the tokens currently owned by a specified account, including NFTs and fungible tokens. If desired, you can filter the results by a specific token standard.
The account address for which to retrieve owned tokens.
OptionalminimumLedgerVersion?: AnyNumberOptional ledger version to sync up to before querying.
Optionaloptions?: TokenStandardArg & PaginationArgs & OrderByArg<An array of tokens with their respective data.
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 tokens owned by a specific account
const accountOwnedTokens = await aptos.getAccountOwnedTokens({
accountAddress: "0x1", // replace with a real account address
options: {
limit: 10, // specify how many tokens to return
orderBy: "created_at", // specify the order of the results
},
});
console.log(accountOwnedTokens);
}
runExample().catch(console.error);
Queries all current tokens of a specific collection that an account owns by the collection address. This query returns all tokens (v1 and v2 standards) an account owns, including NFTs, fungible, soulbound, etc. If you want to get only the token from a specific standard, you can pass an optional tokenStandard parameter.
The account address we want to get the tokens for.
The address of the collection being queried.
OptionalminimumLedgerVersion?: AnyNumberOptional ledger version to sync up to, before querying.
Optionaloptions?: TokenStandardArg & PaginationArgs & OrderByArg<Tokens array with the token data.
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 tokens owned by a specific account in a specific collection
const accountOwnedTokens = await aptos.getAccountOwnedTokensFromCollectionAddress({
accountAddress: "0x1", // replace with a real account address
collectionAddress: "0x2", // replace with a real collection address
});
console.log(accountOwnedTokens);
}
runExample().catch(console.error);
Queries a specific account resource given an account address and resource type.
The typed output of the resource.
The Aptos account address to query.
Optionaloptions?: LedgerVersionArgThe string representation of an on-chain Move struct type, e.g., "0x1::aptos_coin::AptosCoin".
The account resource of the specified type.
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 account resource for a specific account address and resource type
const resource = await aptos.getAccountResource({
accountAddress: "0x1", // replace with a real account address
resourceType: "0x1::aptos_coin::AptosCoin"
});
console.log(resource);
}
runExample().catch(console.error);
Queries all account resources given an account address. This function may call the API multiple times to auto paginate through results.
The Aptos account address to query resources for.
Optionaloptions?: PaginationArgs & LedgerVersionArgAccount resources.
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 account resources for a specific account address
const resources = await aptos.getAccountResources({ accountAddress: "0x1" }); // replace with a real account address
console.log(resources);
}
runExample().catch(console.error);
Queries a page of account resources given an account address.
The Aptos account address to query resources for.
Optionaloptions?: CursorPaginationArgs & LedgerVersionArgAccount resources.
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 account resources for a specific account address
const resources = await aptos.getAccountResourcesPage({
accountAddress: "0x1", // replace with a real account address
options: {
cursor: undefined, // starting from the first resource
limit: 10, // limiting to 10 resources
},
});
console.log(resources);
console.log(`More to fetch: ${resources.cursor !== undefined}`);
}
runExample().catch(console.error);
Gets all account info (address, account public key, last transaction version) that have are associated with a public key and related public keys
For a given public key, it will query all multikeys that the public key is part of. Then for the provided public key and any multikeys found in the previous step, it will query for any accounts that have an auth key that matches any of the public keys.
Note: If an Ed25519PublicKey or an AnyPublicKey that wraps Ed25519PublicKey is passed in, it will query for both legacy and single singer cases.
The arguments for getting accounts for a public key
OptionalminimumLedgerVersion?: AnyNumberThe minimum ledger version to wait for before querying
Optionaloptions?: { includeUnverified?: boolean; noMultiKey?: boolean }OptionalincludeUnverified?: booleanWhether to include unverified accounts in the results. Unverified accounts are accounts that can be authenticated with the signer, but there is no history of the signer using the account. Default is false.
OptionalnoMultiKey?: booleanWhether to exclude multi-key accounts in the results. Default is false.
The public key to look up accounts for
Promise resolving to an array of account addresses and their associated public keys
import { Aptos, AptosConfig, Network, Ed25519PrivateKey } from "@aptos-labs/ts-sdk";
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
async function getAccounts() {
const privateKey = Ed25519PrivateKey.generate();
const publicKey = privateKey.publicKey();
const accounts = await aptos.getAccountsForPublicKey({
publicKey
});
console.log(accounts);
}
Queries the current count of tokens owned by a specified account.
The parameters for the query.
The account address to query the token count for.
OptionalminimumLedgerVersion?: AnyNumberOptional ledger version to sync up to before querying.
The current count of tokens owned by the account.
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 count of tokens owned by the account
const tokensCount = await aptos.getAccountTokensCount({ accountAddress: "0x1" }); // replace with a real account address
console.log(`Tokens Count: ${tokensCount}`);
}
runExample().catch(console.error);
Queries account transactions given an account address. This function may call the API multiple times to auto paginate and retrieve all account transactions.
The Aptos account address to query transactions for.
Optionaloptions?: PaginationArgsOptional pagination arguments.
The account transactions.
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 transactions for a specific account
const transactions = await aptos.getAccountTransactions({
accountAddress: "0x1", // replace with a real account address
options: {
offset: 0, // starting from the first transaction
limit: 10, // limiting to 10 transactions
},
});
console.log(transactions);
}
runExample().catch(console.error);
Queries the current count of transactions submitted by an account.
The parameters for the query.
The account address we want to get the total count for.
OptionalminimumLedgerVersion?: AnyNumberOptional ledger version to sync up to before querying.
Current count of transactions made by an account.
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 count of transactions for a specific account
const accountTransactionsCount = await aptos.getAccountTransactionsCount({
accountAddress: "0x1", // replace with a real account address
minimumLedgerVersion: 1, // specify your own minimum ledger version if needed
});
console.log(accountTransactionsCount);
}
runExample().catch(console.error);
Looks up the account address for a given authentication key, handling both rotated and non-rotated keys.
The authentication key for which to look up the account address.
OptionalminimumLedgerVersion?: AnyNumberOptional ledger version to sync up to before querying.
Optionaloptions?: LedgerVersionArgPromise
import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
async function runExample() {
// Look up the original account address for a given authentication key
const accountAddress = await aptos.lookupOriginalAccountAddress({
authenticationKey: "0x1", // replace with a real authentication key
});
console.log("Original Account Address:", accountAddress);
}
runExample().catch(console.error);
Generate a transfer coin transaction that can be simulated, signed, and submitted. This function helps you create a transaction to transfer a specified amount of coins from one account to another within the Aptos network.
The arguments for the transfer transaction.
The amount of coins to transfer.
OptionalcoinType?: `${string}::${string}::${string}`Optional. The coin struct type to transfer. Defaults to 0x1::aptos_coin::AptosCoin.
Optionaloptions?: InputGenerateTransactionOptionsOptional. Additional options for generating the transaction.
The recipient account address.
The sender account address.
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() {
// Generate a transfer coin transaction
const transaction = await aptos.transferCoinTransaction({
sender: "0x1", // replace with a real sender account address
recipient: "0x2", // replace with a real recipient account address
amount: 10,
});
console.log(transaction);
}
runExample().catch(console.error);
Add a digital asset property to the blockchain. This function allows you to specify a new property for a digital asset, including its key, type, and value.
The arguments for adding a digital asset property.
The account that mints the digital asset.
The digital asset address.
OptionaldigitalAssetType?: `${string}::${string}::${string}`(Optional) The type of the digital asset.
Optionaloptions?: InputGenerateTransactionOptions(Optional) Options for generating the transaction.
The property key for storing on-chain properties.
The type of property value.
The property value to be stored on-chain.
A SimpleTransaction that can be simulated or submitted to the chain.
import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
async function runExample() {
// Add a digital asset property
const transaction = await aptos.addDigitalAssetPropertyTransaction({
creator: Account.generate(), // Replace with a real account
propertyKey: "newKey",
propertyType: "BOOLEAN",
propertyValue: true,
digitalAssetAddress: "0x123", // Replace with a real digital asset address
});
console.log(transaction);
}
runExample().catch(console.error);
Add a typed digital asset property to the blockchain. This function allows you to define and store a specific property for a digital asset, enabling better categorization and management of digital assets.
The parameters for adding the typed property.
The account that mints the digital asset.
The digital asset address.
OptionaldigitalAssetType?: `${string}::${string}::${string}`The optional type of the digital asset.
Optionaloptions?: InputGenerateTransactionOptionsOptional transaction generation options.
The property key for storing on-chain properties.
The type of property value.
The property value to be stored on-chain.
A SimpleTransaction that can be simulated or submitted to the chain.
import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
async function runExample() {
// Adding a typed digital asset property
const transaction = await aptos.addDigitalAssetTypedPropertyTransaction({
creator: Account.generate(), // replace with a real account
propertyKey: "typedKey",
propertyType: "STRING",
propertyValue: "hello",
digitalAssetAddress: "0x123", // replace with a real digital asset address
});
console.log(transaction);
}
runExample().catch(console.error);
Burn a digital asset by its creator, allowing for the removal of a specified digital asset from the blockchain.
The arguments for burning the digital asset.
The creator account that is burning the digital asset.
The address of the digital asset to be burned.
OptionaldigitalAssetType?: `${string}::${string}::${string}`Optional. The type of the digital asset being burned.
Optionaloptions?: InputGenerateTransactionOptionsOptional. Additional options for generating the transaction.
A SimpleTransaction that can be simulated or submitted to the chain.
import { Aptos, AptosConfig, Network, Account } from "@aptos-labs/ts-sdk";
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
async function runExample() {
const creator = Account.generate(); // Replace with a real creator account
const transaction = await aptos.burnDigitalAssetTransaction({
creator: creator,
digitalAssetAddress: "0x123", // Replace with a real digital asset address
});
console.log(transaction);
}
runExample().catch(console.error);
Creates a new collection within the specified account.
The account of the collection's creator.
The description of the collection.
The name of the collection.
Optionaloptions?: InputGenerateTransactionOptionsOptional parameters for generating the transaction.
The parameters below are optional:
The URI to additional info about the collection.
Options for creating a collection, allowing customization of various attributes such as supply limits, mutability of metadata, and royalty settings.
OptionalmaxSupply?: AnyNumberOptionalmutableDescription?: booleanOptionalmutableRoyalty?: booleanOptionalmutableTokenDescription?: booleanOptionalmutableTokenName?: booleanOptionalmutableTokenProperties?: booleanOptionalmutableTokenURI?: booleanOptionalmutableURI?: booleanOptionalroyaltyDenominator?: numberOptionalroyaltyNumerator?: numberOptionaltokensBurnableByCreator?: booleanOptionaltokensFreezableByCreator?: booleanA SimpleTransaction that when submitted will create the collection.
import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
async function runExample() {
// Creating a new collection transaction
const transaction = await aptos.createCollectionTransaction({
creator: Account.generate(), // Replace with a real account
description: "A unique collection of digital assets.",
name: "My Digital Collection",
uri: "https://mycollection.com",
});
console.log("Transaction created:", transaction);
}
runExample().catch(console.error);
Freeze the ability to transfer a specified digital asset. This function allows the creator to restrict the transfer capability of a digital asset.
The arguments for freezing the digital asset transfer.
The creator account initiating the freeze.
The address of the digital asset to be frozen.
OptionaldigitalAssetType?: `${string}::${string}::${string}`Optional. The type of the digital asset being frozen.
Optionaloptions?: InputGenerateTransactionOptionsOptional. Additional options for generating the transaction.
A SimpleTransaction that can be simulated or submitted to the chain.
import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
async function runExample() {
// Freeze the digital asset transfer
const transaction = await aptos.freezeDigitalAssetTransaferTransaction({
creator: Account.generate(), // Replace with a real account if needed
digitalAssetAddress: "0x123", // Replace with a real digital asset address
});
console.log(transaction);
}
runExample().catch(console.error);
Queries data of a specific collection by the collection creator address and the collection name.
This function is deprecated; use getCollectionDataByCreatorAddressAndCollectionName instead.
If a creator account has two collections with the same name in v1 and v2, you can pass an optional tokenStandard parameter
to query a specific standard.
The arguments for querying the collection data.
The name of the collection.
The address of the collection's creator.
OptionalminimumLedgerVersion?: AnyNumberOptional ledger version to sync up to before querying.
Optionaloptions?: TokenStandardArgOptional parameters for the query.
GetCollectionDataResponse - The response type containing the collection data.
import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
async function runExample() {
// Querying collection data by creator address and collection name
const collection = await aptos.getCollectionData({
creatorAddress: "0x1", // replace with a real creator address
collectionName: "myCollection", // specify your collection name
});
console.log(collection);
}
runExample().catch(console.error);
Queries data of a specific collection by the collection ID.
The ID of the collection, which is the same as the address of the collection object.
OptionalminimumLedgerVersion?: AnyNumberOptional ledger version to sync up to before querying.
Optionaloptions?: TokenStandardArg & PaginationArgsOptional parameters for token standard and pagination.
GetCollectionDataResponse - The response type containing the collection data.
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 collection data by collection ID
const collection = await aptos.getCollectionDataByCollectionId({
collectionId: "0x123", // replace with a real collection ID
});
console.log(collection);
}
runExample().catch(console.error);
Retrieves data for a specific collection created by a given creator address. This function allows you to query collection data while optionally specifying a minimum ledger version and pagination options.
The address of the collection's creator.
OptionalminimumLedgerVersion?: AnyNumberOptional ledger version to sync up to before querying.
Optionaloptions?: TokenStandardArg & PaginationArgsGetCollectionDataResponse - The response type containing collection data.
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 collection data by creator address
const collectionData = await aptos.getCollectionDataByCreatorAddress({
creatorAddress: "0x1", // replace with a real creator address
minimumLedgerVersion: 1, // specify the minimum ledger version if needed
options: {
tokenStandard: "v2", // specify the token standard if needed
pagination: { limit: 10, offset: 0 } // specify pagination options if needed
}
});
console.log(collectionData);
}
runExample().catch(console.error);
Queries data of a specific collection by the collection creator address and the collection name.
If a creator account has multiple collections with the same name across different versions,
specify the tokenStandard parameter to query a specific standard.
The name of the collection.
The address of the collection's creator.
OptionalminimumLedgerVersion?: AnyNumberOptional ledger version to sync up to before querying.
Optionaloptions?: TokenStandardArg & PaginationArgsGetCollectionDataResponse - The response type containing collection data.
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 collection data by creator address and collection name
const collection = await aptos.getCollectionDataByCreatorAddressAndCollectionName({
creatorAddress: "0x1", // replace with a real creator address
collectionName: "myCollection",
minimumLedgerVersion: 1, // optional, specify if needed
options: { tokenStandard: "v2" } // optional, specify if needed
});
console.log(collection);
}
runExample().catch(console.error);
Queries the ID of a specified collection. This ID corresponds to the collection's object address in V2, while V1 does not utilize objects and lacks an address.
The name of the collection.
The address of the collection's creator.
OptionalminimumLedgerVersion?: AnyNumberOptional ledger version to sync up to before querying.
Optionaloptions?: TokenStandardArgThe collection ID.
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 the collection ID for a specific creator and collection name
const collectionId = await aptos.getCollectionId({
creatorAddress: "0x1", // replace with a real creator address
collectionName: "myCollection"
});
console.log("Collection ID:", collectionId);
}
runExample().catch(console.error);
Retrieves the current ownership data of a specified digital asset using its address.
The parameters for the request.
The address of the digital asset.
OptionalminimumLedgerVersion?: AnyNumberOptional ledger version to sync up to before querying.
GetCurrentTokenOwnershipResponse containing relevant ownership data of the digital asset.
import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
async function runExample() {
// Getting the current ownership of a digital asset
const digitalAssetOwner = await aptos.getCurrentDigitalAssetOwnership({
digitalAssetAddress: "0x123", // replace with a real digital asset address
});
console.log(digitalAssetOwner);
}
runExample().catch(console.error);
Retrieves the activity data for a specified digital asset using its address.
The parameters for the request.
The address of the digital asset.
OptionalminimumLedgerVersion?: AnyNumberOptional minimum ledger version to sync up to before querying.
Optionaloptions?: PaginationArgs & OrderByArg<Optional pagination and ordering parameters.
A promise that resolves to the activity data related to the digital asset.
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 activity data for a digital asset
const digitalAssetActivity = await aptos.getDigitalAssetActivity({
digitalAssetAddress: "0x123", // replace with a real digital asset address
});
console.log(digitalAssetActivity);
}
runExample().catch(console.error);
Retrieves digital asset data using the address of a digital asset.
The parameters for the request.
The address of the digital asset.
OptionalminimumLedgerVersion?: AnyNumberOptional ledger version to sync up to before querying.
GetTokenDataResponse containing relevant data for the digital asset.
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 digital asset data for a specific address
const digitalAsset = await aptos.getDigitalAssetData({
digitalAssetAddress: "0x123", // replace with a real digital asset address
});
console.log(digitalAsset);
}
runExample().catch(console.error);
Retrieves the digital assets owned by a specified address.
OptionalminimumLedgerVersion?: AnyNumberOptional ledger version to sync up to before querying.
Optionaloptions?: PaginationArgs & OrderByArg<Optional pagination and ordering parameters for the response.
The address of the owner.
GetOwnedTokensResponse containing ownership data of the digital assets belonging to the ownerAddress.
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 the digital assets owned by the specified address
const digitalAssets = await aptos.getOwnedDigitalAssets({
ownerAddress: "0x1", // replace with a real account address
});
console.log(digitalAssets);
}
runExample().catch(console.error);
Create a transaction to mint a digital asset into the creator's account within an existing collection. This function helps you generate a transaction that can be simulated or submitted to the blockchain for minting a digital asset.
The name of the collection the digital asset belongs to.
The creator of the collection.
The description of the digital asset.
The name of the digital asset.
Optionaloptions?: InputGenerateTransactionOptionsOptional transaction generation options.
OptionalpropertyKeys?: string[]Optional array of property keys for the digital asset.
OptionalpropertyTypes?: (Optional array of property types for the digital asset.
OptionalpropertyValues?: PropertyValue[]Optional array of property values for the digital asset.
The URI to additional info about the digital asset.
A SimpleTransaction that can be simulated or submitted to the chain.
import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
async function runExample() {
// Creating a transaction to mint a digital asset
const transaction = await aptos.mintDigitalAssetTransaction({
creator: Account.generate(), // replace with a real account
collection: "MyCollection",
description: "This is a digital asset.",
name: "MyDigitalAsset",
uri: "https://example.com/my-digital-asset",
});
console.log(transaction);
}
runExample().catch(console.error);
Mint a soul bound digital asset into a recipient's account. This function allows you to create a unique digital asset that is bound to a specific account.
The arguments for minting the soul bound transaction.
The account that mints the digital asset.
The collection name that the digital asset belongs to.
The digital asset description.
The digital asset name.
Optionaloptions?: InputGenerateTransactionOptionsAdditional options for generating the transaction.
OptionalpropertyKeys?: string[]The property keys for storing on-chain properties.
OptionalpropertyTypes?: (The type of property values.
OptionalpropertyValues?: PropertyValue[]The property values to be stored on-chain.
The account address where the digital asset will be created.
The digital asset URL.
A SimpleTransaction that can be simulated or submitted to the chain.
import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
async function runExample() {
// Mint a soul bound digital asset
const transaction = await aptos.mintSoulBoundTransaction({
account: Account.generate(), // Replace with a real account
collection: "collectionName",
description: "collectionDescription",
name: "digitalAssetName",
uri: "digital-asset-uri.com",
recipient: "0x123" // Replace with a real recipient account address
});
console.log(transaction);
}
runExample().catch(console.error);
Remove a digital asset property from the blockchain. This function allows you to delete an existing property associated with a digital asset.
The parameters required to remove the digital asset property.
The account that mints the digital asset.
The digital asset address.
OptionaldigitalAssetType?: `${string}::${string}::${string}`Optional. The type of the digital asset.
Optionaloptions?: InputGenerateTransactionOptionsOptional. Additional options for generating the transaction.
The property key for storing on-chain properties.
The type of property value.
The property value to be stored on-chain.
A SimpleTransaction that can be simulated or submitted to the chain.
import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
async function runExample() {
// Remove a digital asset property
const transaction = await aptos.removeDigitalAssetPropertyTransaction({
creator: Account.generate(), // replace with a real account
propertyKey: "newKey",
propertyType: "BOOLEAN",
propertyValue: true,
digitalAssetAddress: "0x123", // replace with a real digital asset address
});
console.log(transaction);
}
runExample().catch(console.error);
Set the digital asset description to provide additional context or information about the asset.
The parameters for setting the digital asset description.
The creator account responsible for the digital asset.
The digital asset description to be set.
The address of the digital asset.
OptionaldigitalAssetType?: `${string}::${string}::${string}`Optional. The type of the digital asset.
Optionaloptions?: InputGenerateTransactionOptionsOptional. Additional options for generating the transaction.
A SimpleTransaction that can be simulated or submitted to the chain.
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 digital asset description
const transaction = await aptos.setDigitalAssetDescriptionTransaction({
creator: Account.generate(), // replace with a real account
description: "This is a digital asset description.",
digitalAssetAddress: "0x123", // replace with a real digital asset address
});
console.log(transaction);
}
runExample().catch(console.error);
Set the digital asset name, allowing you to define a name for a specific digital asset on the blockchain.
The parameters for setting the digital asset name.
The creator account responsible for the transaction.
The address of the digital asset.
OptionaldigitalAssetType?: `${string}::${string}::${string}`Optional. The type of the digital asset, represented as a Move struct ID.
The desired name for the digital asset.
Optionaloptions?: InputGenerateTransactionOptionsOptional. Additional options for generating the transaction.
A SimpleTransaction that can be simulated or submitted to the blockchain.
import { Aptos, AptosConfig, Network, Account } from "@aptos-labs/ts-sdk";
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
async function runExample() {
const creator = Account.generate(); // Generate a new account for the creator
const digitalAssetAddress = "0x123"; // replace with a real digital asset address
// Set the digital asset name
const transaction = await aptos.setDigitalAssetNameTransaction({
creator: creator,
name: "digitalAssetName",
digitalAssetAddress: digitalAssetAddress,
});
console.log(transaction);
}
runExample().catch(console.error);
Set the URI for a digital asset, allowing you to associate a unique identifier with the asset.
The parameters for the transaction.
The creator account initiating the transaction.
The address of the digital asset.
OptionaldigitalAssetType?: `${string}::${string}::${string}`Optional. The type of the digital asset.
Optionaloptions?: InputGenerateTransactionOptionsOptional. Additional options for generating the transaction.
The digital asset URI to be set.
A SimpleTransaction that can be simulated or submitted to the chain.
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 URI for a digital asset
const transaction = await aptos.setDigitalAssetURITransaction({
creator: Account.generate(), // Replace with a real creator account
uri: "digital-asset-uri.com",
digitalAssetAddress: "0x123", // Replace with a real digital asset address
});
console.log(transaction);
}
runExample().catch(console.error);
Transfer ownership of a non-fungible digital asset. This function allows you to transfer a digital asset only if it is not frozen, meaning the ownership transfer is not disabled.
The arguments for transferring the digital asset.
The address of the digital asset being transferred.
OptionaldigitalAssetType?: `${string}::${string}::${string}`Optional. The type of the digital asset, defaults to "0x4::token::Token".
Optionaloptions?: InputGenerateTransactionOptionsOptional. Additional options for generating the transaction.
The account address of the recipient.
The sender account of the current digital asset owner.
A SimpleTransaction that can be simulated or submitted to the chain.
import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
async function runExample() {
// Transfer a digital asset
const transaction = await aptos.transferDigitalAssetTransaction({
sender: Account.generate(), // replace with a real sender account
digitalAssetAddress: "0x123", // replace with a real digital asset address
recipient: "0x456", // replace with a real recipient account address
});
console.log(transaction);
}
runExample().catch(console.error);
Unfreeze the ability to transfer a digital asset. This function allows the specified creator account to unfreeze the transfer of a digital asset identified by its address.
The parameters for unfreezing the digital asset transfer.
The creator account that is unfreezing the digital asset transfer.
The address of the digital asset to unfreeze.
OptionaldigitalAssetType?: `${string}::${string}::${string}`Optional. The type of the digital asset being unfrozen.
Optionaloptions?: InputGenerateTransactionOptionsOptional. Additional options for generating the transaction.
A SimpleTransaction that can be simulated or submitted to the chain.
import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
async function runExample() {
// Unfreeze the ability to transfer a digital asset
const transaction = await aptos.unfreezeDigitalAssetTransaferTransaction({
creator: Account.generate(), // replace with a real creator account
digitalAssetAddress: "0x123", // replace with a real digital asset address
});
console.log(transaction);
}
runExample().catch(console.error);
Update a digital asset property on-chain.
The parameters for updating the digital asset property.
The account that mints the digital asset.
The address of the digital asset.
OptionaldigitalAssetType?: `${string}::${string}::${string}`Optional. The type of the digital asset.
Optionaloptions?: InputGenerateTransactionOptionsOptional. Additional options for generating the transaction.
The property key for storing on-chain properties.
The type of property value.
The property value to be stored on-chain.
A SimpleTransaction that can be simulated or submitted to the chain.
import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
async function runExample() {
// Update a digital asset property
const transaction = await aptos.updateDigitalAssetPropertyTransaction({
creator: Account.generate(), // replace with a real account
propertyKey: "newKey",
propertyType: "BOOLEAN",
propertyValue: false,
digitalAssetAddress: "0x123", // replace with a real digital asset address
});
console.log(transaction);
}
runExample().catch(console.error);
Update a typed digital asset property on-chain. This function allows you to modify the properties of a digital asset, enabling dynamic updates to its attributes.
The arguments for updating the digital asset property.
The account that mints the digital asset.
The digital asset address.
OptionaldigitalAssetType?: `${string}::${string}::${string}`(Optional) The type of the digital asset.
Optionaloptions?: InputGenerateTransactionOptions(Optional) Additional options for generating the transaction.
The property key for storing on-chain properties.
The type of property value.
The property value to be stored on-chain.
A SimpleTransaction that can be simulated or submitted to the chain.
import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
async function runExample() {
// Update a typed digital asset property
const transaction = await aptos.updateDigitalAssetTypedPropertyTransaction({
creator: Account.generate(), // replace with a real account
propertyKey: "typedKey",
propertyType: "U8",
propertyValue: 2,
digitalAssetAddress: "0x123", // replace with a real digital asset address
});
console.log(transaction);
}
runExample().catch(console.error);
Retrieve events associated with a specific account address and creation number.
The parameters for retrieving account events.
The account address to query events for.
The event creation number to filter the events.
OptionalminimumLedgerVersion?: AnyNumberOptional minimum ledger version to sync up to before querying.
Promise
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 events for the account at creation number 0
const events = await aptos.getAccountEventsByCreationNumber({
accountAddress: "0x1", // replace with a real account address
creationNumber: 0,
});
console.log(events);
}
runExample().catch(console.error);
Retrieve events associated with a specific account address and event type.
The account address to query events for.
The type of event to filter by.
OptionalminimumLedgerVersion?: AnyNumberOptional ledger version to sync up to before querying.
Optionaloptions?: PaginationArgs & OrderByArg<Optional pagination and ordering parameters for the event query.
Promise
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 events for a specific account and event type
const events = await aptos.getAccountEventsByEventType({
accountAddress: "0x1", // replace with a real account address
eventType: "0x1::transaction_fee::FeeStatement", // replace with a real event type
minimumLedgerVersion: 1, // optional, specify if needed
});
console.log(events);
}
runExample().catch(console.error);
Retrieve all events from the Aptos blockchain.
An optional where clause can be provided to filter the results based on specific criteria.
Optionalargs: {Optional parameters for the query.
OptionalminimumLedgerVersion?: AnyNumberOptional ledger version to sync up to before querying.
Optionaloptions?: PaginationArgs & OrderByArg<Optional pagination and filtering options.
GetEventsQuery response type containing the events.
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 all events
const events = await aptos.getEvents();
// Retrieve events with filtering by account address
const whereCondition = {
account_address: { _eq: "0x123" }, // replace with a real account address
};
const filteredEvents = await aptos.getEvents({
options: { where: whereCondition },
});
console.log(events);
console.log(filteredEvents);
}
runExample().catch(console.error);
Retrieve module events based on a specified event type. This function allows you to query for events that are associated with a particular module event type in the Aptos blockchain.
The arguments for retrieving module events.
The event type to filter the results.
OptionalminimumLedgerVersion?: AnyNumberOptional ledger version to sync up to before querying.
Optionaloptions?: PaginationArgs & OrderByArg<Optional pagination and ordering parameters for the event results.
Promise
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 module events for a specific event type
const events = await aptos.getModuleEventsByEventType({
eventType: "0x1::transaction_fee::FeeStatement", // specify the event type
minimumLedgerVersion: 1, // optional: specify minimum ledger version if needed
});
console.log(events); // log the retrieved events
}
runExample().catch(console.error);
This function creates an account if it does not exist and mints the specified amount of coins into that account.
Note that only devnet has a publicly accessible faucet. For testnet, you must use the minting page at https://aptos.dev/network/faucet.
The arguments for funding the account.
The address of the account to fund.
The amount of tokens to fund the account with.
Optionaloptions?: WaitForTransactionOptionsConfiguration options for waiting for the transaction.
Transaction hash of the transaction that funded the account.
import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";
const config = new AptosConfig({ network: Network.DEVNET });
const aptos = new Aptos(config);
async function runExample() {
// Fund an account with a specified amount of tokens
const transaction = await aptos.fundAccount({
accountAddress: "0x1", // replace with your account address
amount: 100,
});
console.log("Transaction hash:", transaction.hash);
}
runExample().catch(console.error);
Queries all fungible asset balances.
Optionalargs: {Optional parameters for the query.
OptionalminimumLedgerVersion?: AnyNumberOptional ledger version to sync up to, before querying.
Optionaloptions?: PaginationArgs & WhereArg<CurrentFungibleAssetBalancesBoolExp>Optional configuration for pagination and filtering.
A list of fungible asset metadata.
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 current fungible asset balances
const fungibleAssetBalances = await aptos.getCurrentFungibleAssetBalances();
console.log(fungibleAssetBalances);
}
runExample().catch(console.error);
Queries all fungible asset activities and returns a list of their metadata.
Optionalargs: {Optional parameters for the query.
OptionalminimumLedgerVersion?: AnyNumberOptional ledger version to sync up to, before querying.
Optionaloptions?: PaginationArgs & WhereArg<FungibleAssetActivitiesBoolExp>Optional configuration for pagination and filtering.
A list of fungible asset metadata.
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 fungible asset activities
const fungibleAssetActivities = await aptos.getFungibleAssetActivities();
console.log(fungibleAssetActivities);
}
runExample().catch(console.error);
Queries all fungible asset metadata.
Optionalargs: {Optional parameters for the query.
OptionalminimumLedgerVersion?: AnyNumberOptional ledger version to sync up to before querying.
Optionaloptions?: PaginationArgs & WhereArg<FungibleAssetMetadataBoolExp>Optional configuration for pagination and filtering.
A list of fungible asset metadata.
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 fungible asset metadata
const fungibleAssets = await aptos.getFungibleAssetMetadata();
console.log(fungibleAssets);
}
runExample().catch(console.error);
Queries the fungible asset metadata for a specific asset type. This function helps retrieve detailed information about a fungible asset based on its type.
A fungible asset metadata item.
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 fungible asset metadata by asset type
const fungibleAsset = await aptos.getFungibleAssetMetadataByAssetType({
assetType: "0x1::aptos_coin::AptosCoin" // replace with your asset type
});
console.log(fungibleAsset);
}
runExample().catch(console.error);
Retrieves fungible asset metadata based on the creator address.
This function allows you to query metadata for a specific fungible asset created by a given address.
The parameters for the query.
The creator address of the fungible asset.
OptionalminimumLedgerVersion?: AnyNumberOptional ledger version to sync up to before querying.
A fungible asset metadata item.
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 fungible asset metadata by creator address
const fungibleAsset = await aptos.getFungibleAssetMetadataByCreatorAddress({
creatorAddress: "0x123", // replace with a real creator address
});
console.log(fungibleAsset);
}
runExample().catch(console.error);
Transfer a specified amount of fungible asset from the sender's primary store to the recipient's primary store. This method allows you to transfer any fungible asset, including fungible tokens.
The arguments for the transfer operation.
The number of assets to transfer.
The fungible asset account address. For example, if you're transferring USDT, this would be the USDT address.
Optionaloptions?: InputGenerateTransactionOptionsOptional parameters for generating the transaction.
The recipient account address.
The sender account.
A SimpleTransaction that can be simulated or submitted to the chain.
import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
async function runExample() {
// Transfer fungible asset from sender to recipient
const transaction = await aptos.transferFungibleAsset({
sender: Account.generate(), // replace with a real sender account
fungibleAssetMetadataAddress: "0x123", // replace with a real fungible asset address
recipient: "0x456", // replace with a real recipient account
amount: 5
});
console.log(transaction);
}
runExample().catch(console.error);
Transfer a specified amount of fungible asset from the sender's any (primary or secondary) fungible store to any (primary or secondary) fungible store. This method allows you to transfer any fungible asset, including fungible tokens.
The arguments for the transfer operation.
The number of assets to transfer. Must be a positive number.
The fungible store address initiating the transfer.
Optionaloptions?: InputGenerateTransactionOptionsOptional parameters for generating the transaction.
The sender account initiating the transfer.
The fungible store address receiving the asset.
A SimpleTransaction that can be simulated or submitted to the chain.
Error if:
import { Aptos, AptosConfig, Network, Account } from "@aptos-labs/ts-sdk";
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
async function transferAssets() {
// Transfer 100 units of the asset from senderStore to recipientStore
const transaction = await aptos.transferFungibleAssetBetweenStores({
sender: Account.generate(), // replace with a real sender account
fromStore: "0x123", // replace with a real fungible store address
toStore: "0x456", // replace with a real fungible store address
amount: 100
});
console.log(transaction);
}
transferAssets().catch(console.error);
Retrieve a block by its height, allowing for the inclusion of transactions if specified.
The parameters for the block retrieval.
The block height to look up, starting at 0.
Optionaloptions?: { withTransactions?: boolean }Optional settings for the retrieval.
OptionalwithTransactions?: booleanIf set to true, includes all transactions in the block.
The block with optional transactions included.
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 block at height 5, including transactions
const block = await aptos.getBlockByHeight({ blockHeight: 5, options: { withTransactions: true } });
console.log(block);
}
runExample().catch(console.error);
Retrieves block information by the specified ledger version.
The arguments for retrieving the block.
The ledger version to lookup block information for.
Optionaloptions?: { withTransactions?: boolean }Optional parameters for the request.
OptionalwithTransactions?: booleanIf set to true, include all transactions in the block.
Block information with optional transactions.
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 block information for a specific ledger version
const block = await aptos.getBlockByVersion({ ledgerVersion: 5 });
console.log(block);
}
runExample().catch(console.error);
Retrieves the chain ID of the Aptos blockchain.
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 the chain ID
const chainId = await aptos.getChainId();
console.log("Chain ID:", chainId);
}
runExample().catch(console.error);
@returns The chain ID of the Aptos blockchain.
Queries the top user transactions based on the specified limit.
The arguments for querying top user transactions.
The number of transactions to return.
GetChainTopUserTransactionsResponse
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 the top user transactions with a limit of 5
const topUserTransactions = await aptos.getChainTopUserTransactions({ limit: 5 });
console.log(topUserTransactions);
}
runExample().catch(console.error);
Queries for the last successful indexer version, providing insight into the ledger version the indexer is updated to, which may lag behind the full nodes.
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 last successful indexer version
const version = await aptos.getIndexerLastSuccessVersion();
console.log(`Last successful indexer version: ${version}`);
}
runExample().catch(console.error);
Queries for the Aptos ledger information.
The Aptos Ledger Info, which includes details such as chain ID, epoch, and ledger version.
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 the ledger information
const ledgerInfo = await aptos.getLedgerInfo();
console.log(ledgerInfo);
}
runExample().catch(console.error);
Query the processor status for a specific processor type.
The processor type to query.
The status of the specified processor type.
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 processor status for the account transactions processor
const status = await aptos.getProcessorStatus("account_transactions_processor");
console.log(status);
}
runExample().catch(console.error);
Retrieves data from the Aptos Indexer using a GraphQL query. This function allows you to execute complex queries to fetch specific data from the Aptos blockchain.
The provided T type.
import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
async function runExample() {
// Querying the Aptos Indexer for ledger information
const topUserTransactions = await aptos.queryIndexer({
query: { query: `query MyQuery {
ledger_infos {
chain_id
}
}`}
});
console.log(topUserTransactions);
}
runExample().catch(console.error);
Queries for a Move view function
Optionaloptions?: LedgerVersionArgPayload for the view function
an array of Move values
Queries for a Move view function with JSON, this provides compatability with the old aptos package
Optionaloptions?: LedgerVersionArgPayload for the view function
an array of Move values
Fetches the pepper from the Aptos pepper service API.
The arguments for fetching the pepper.
OptionalderivationPath?: stringA derivation path used for creating multiple accounts per user via the BIP-44 standard. Defaults to "m/44'/637'/0'/0'/0".
The EphemeralKeyPair used to generate the nonce in the JWT token.
JWT token.
The pepper which is a Uint8Array of length 31.
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 ephemeralKeyPair = new EphemeralKeyPair(); // create a new ephemeral key pair
const jwt = "your_jwt_token"; // replace with a real JWT token
// Fetching the pepper using the provided JWT and ephemeral key pair
const pepper = await aptos.getPepper({
jwt,
ephemeralKeyPair,
// derivationPath: "m/44'/637'/0'/0'/0" // specify your own if needed
});
console.log("Fetched pepper:", pepper);
}
runExample().catch(console.error);
Fetches a proof from the Aptos prover service API.
The arguments for fetching the proof.
The EphemeralKeyPair used to generate the nonce in the JWT token.
JWT token.
Optionalpepper?: HexInputThe pepper used for the account. If not provided, it will be fetched from the Aptos pepper service.
OptionaluidKey?: stringA key in the JWT token to use to set the uidVal in the IdCommitment.
The proof which is represented by a ZeroKnowledgeSig.
import { Aptos, AptosConfig, Network, EphemeralKeyPair, getPepper } from "@aptos-labs/ts-sdk";
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
async function runExample() {
const jwt = "your_jwt_token"; // replace with a real JWT token
const ephemeralKeyPair = new EphemeralKeyPair(); // create a new ephemeral key pair
// Fetch the proof using the getProof function
const proof = await aptos.getProof({
jwt,
ephemeralKeyPair,
pepper: await getPepper({}), // fetch the pepper if not provided
uidKey: "sub", // specify the uid key
});
console.log("Fetched proof:", proof);
}
runExample().catch(console.error);
This installs a set of FederatedJWKs at an address for a given iss.
It will fetch the JSON Web Keyset (JWK) set from the well-known endpoint and update the FederatedJWKs at the sender's address to reflect it.
the iss claim of the federated OIDC provider.
OptionaljwksUrl?: stringthe URL to find the corresponding JWKs. For supported IDP providers this parameter in not necessary.
Optionaloptions?: InputGenerateTransactionOptionsThe account that will install the JWKs
The pending transaction that results from submission.
Fetches the object data based on the specified object address.
OptionalminimumLedgerVersion?: AnyNumberOptional minimum ledger version to wait for.
The object address to retrieve data for.
Optionaloptions?: PaginationArgs & OrderByArg<Optional configuration options for pagination and ordering.
The object data corresponding to the provided address.
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 object data by object address
const objectData = await aptos.getObjectDataByObjectAddress({
objectAddress: "0x1", // replace with a real object address
});
console.log(objectData);
}
runExample().catch(console.error);
ReadonlyaccountReadonlyansReadonlycoinReadonlyconfigThe configuration settings for the Aptos client.
ReadonlydigitalReadonlyeventReadonlyfaucetReadonlyfungibleReadonlygeneralReadonlykeylessReadonlyobjectReadonlystakingReadonlytableReadonlytransactionQueries delegated staking activities for a specific delegator and pool.
The arguments for querying delegated staking activities.
The address of the delegator.
OptionalminimumLedgerVersion?: AnyNumberOptional ledger version to sync up to before querying.
The address of the staking pool.
The response containing delegated staking activities.
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 delegated staking activities for a specific delegator and pool
const activities = await aptos.getDelegatedStakingActivities({
delegatorAddress: "0x1", // replace with a real delegator address
poolAddress: "0x2", // replace with a real pool address
minimumLedgerVersion: 1, // specify your own if needed
});
console.log(activities);
}
runExample().catch(console.error);
Queries the current number of delegators in a specified pool. Throws an error if the pool is not found.
The parameters for the query.
OptionalminimumLedgerVersion?: AnyNumberOptional ledger version to sync up to before querying.
The address of the pool to query.
The number of delegators for the given pool.
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 number of delegators for a specific pool
const delegators = await aptos.getNumberOfDelegators({ poolAddress: "0x1" }); // replace with a real pool address
console.log(`Number of delegators: ${delegators}`);
}
runExample().catch(console.error);
Retrieves the current number of delegators across all pools.
Optionalargs: {Optional parameters for the query.
OptionalminimumLedgerVersion?: AnyNumberOptional ledger version to sync up to before querying.
Optionaloptions?: OrderByArg<{ num_active_delegator?: any; pool_address?: null | string }>Optional ordering options for the response.
GetNumberOfDelegatorsForAllPoolsResponse response type containing the number of delegators per pool.
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 number of delegators for all pools
const delegators = await aptos.getNumberOfDelegatorsForAllPools();
console.log(delegators);
}
runExample().catch(console.error);
Queries for a specific item in a table identified by the handle and the key for the item. This function allows you to retrieve structured data from a table in the Aptos blockchain.
Object that describes the table item, including key and value types.
A pointer to where that table is stored.
Optionaloptions?: LedgerVersionArgTable item value rendered in JSON.
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 a table item from the Aptos blockchain
const tableItem = await aptos.getTableItem({
handle: "0x1b854694ae746cdbd8d44186ca4929b2b337df21d1c74633be19b2710552fdca",
data: {
key_type: "address", // Move type of table key
value_type: "u128", // Move type of table value
key: "0x619dc29a0aac8fa146714058e8dd6d2d0f3bdf5f6331907bf91f3acd81e6935" // Value of table key
},
});
console.log(tableItem);
}
runExample().catch(console.error);
Queries for table items data with optional filtering and pagination. This function allows you to retrieve specific data from a table based on provided criteria.
The arguments for querying table items data.
OptionalminimumLedgerVersion?: AnyNumberOptional minimum ledger version to wait for before querying.
Optionaloptions?: PaginationArgs & WhereArg<TableItemsBoolExp> & OrderByArg<Optional parameters for pagination and filtering.
GetTableItemsDataResponse
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 table items data with specific filtering options
const data = await aptos.getTableItemsData({
minimumLedgerVersion: 1, // specify your own minimum ledger version if needed
options: {
where: {
table_handle: { _eq: "0x1b854694ae746cdbd8d44186ca4929b2b337df21d1c74633be19b2710552fdca" },
transaction_version: { _eq: "0" }
},
limit: 10, // specify your own limit if needed
},
});
console.log(data);
}
runExample().catch(console.error);
Queries for the metadata of table items, allowing for filtering and pagination.
The parameters for the query.
OptionalminimumLedgerVersion?: AnyNumberOptional minimum ledger version to wait for before querying.
Optionaloptions?: PaginationArgs & WhereArg<TableMetadatasBoolExp> & OrderByArg<Optional parameters for pagination and filtering.
GetTableItemsMetadataResponse
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 table items metadata with a filter condition
const data = await aptos.getTableItemsMetadata({
minimumLedgerVersion: 1, // specify your own minimum ledger version if needed
options: {
where: { handle: { _eq: "0x1b854694ae746cdbd8d44186ca4929b2b337df21d1c74633be19b2710552fdca" } },
limit: 10, // specify your own limit if needed
},
});
console.log(data);
}
runExample().catch(console.error);
The arguments for batching transactions.
An array of transaction payloads to be processed.
Optionaloptions?: Omit<InputGenerateTransactionOptions, "accountSequenceNumber">Optional. Transaction generation configurations (excluding accountSequenceNumber).
The sender account to sign and submit the transactions.
Prefer to use aptos.transaction.batch.forSingleAccount()
Batch transactions for a single account by submitting multiple transaction payloads. This function is useful for efficiently processing and submitting transactions that do not depend on each other, such as batch funding or batch token minting.
import { Aptos, AptosConfig, Network, Account } from "@aptos-labs/ts-sdk";
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
const sender = Account.generate(); // Generate a new account for sending transactions
async function runExample() {
const transactions = [
{ }, // Build your first transaction payload
{ }, // Build your second transaction payload
];
// Batch transactions for the single account
await aptos.batchTransactionsForSingleAccount({
sender,
data: transactions,
});
console.log("Batch transactions submitted successfully.");
}
runExample().catch(console.error);
Estimates the gas unit price required to process a transaction on the Aptos blockchain in a timely manner. This helps users to understand the cost associated with their transactions. https://api.mainnet.aptoslabs.com/v1/spec#/operations/estimate_gas_price
An object containing the estimated gas price.
import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";
const config = new AptosConfig({ network: Network.TESTNET }); // Specify your network
const aptos = new Aptos(config);
async function runExample() {
// Getting the gas price estimation
const gasPriceEstimation = await aptos.getGasPriceEstimation();
console.log("Estimated Gas Price:", gasPriceEstimation);
}
runExample().catch(console.error);
Returns a signing message for a transaction, allowing a user to sign it using their preferred method before submission to the network.
The arguments for obtaining the signing message.
A raw transaction for signing elsewhere.
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 transaction = await aptos.transaction.build.simple({
sender: "0x1", // replace with a real sender address
data: {
function: "0x1::aptos_account::transfer",
functionArguments: ["0x2", 100], // replace with a real destination address
},
});
const message = await aptos.getSigningMessage({ transaction });
console.log(message);
}
runExample().catch(console.error);
Queries on-chain transactions by their transaction hash, returning both pending and committed transactions.
The transaction from the mempool (pending) or the on-chain (committed) transaction.
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 a transaction by its hash
const transaction = await aptos.getTransactionByHash({ transactionHash: "0x123" }); // replace with a real transaction hash
console.log(transaction);
}
runExample().catch(console.error);
Queries on-chain transaction by version. This function will not return pending transactions.
On-chain transaction. Only on-chain transactions have versions, so this function cannot be used to query pending transactions.
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 transaction by its version
const transaction = await aptos.getTransactionByVersion({ ledgerVersion: 1 }); // replace 1 with a real version
console.log(transaction);
}
runExample().catch(console.error);
Queries on-chain transactions, excluding pending transactions. Use this function to retrieve historical transactions from the blockchain.
Optionalargs: { options?: PaginationArgs }Optional parameters for pagination.
Optionaloptions?: PaginationArgsOptional pagination options.
An array of on-chain transactions.
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 transactions with pagination
const transactions = await aptos.getTransactions({
options: {
offset: 0, // Start from the first transaction
limit: 10, // Limit to 10 results
},
});
console.log(transactions);
}
runExample().catch(console.error);
Defines if the specified transaction is currently in a pending state. This function helps you determine the status of a transaction using its hash.
true if the transaction is in a pending state and false 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() {
// Check if the transaction is pending using its hash
const isPendingTransaction = await aptos.isPendingTransaction({ transactionHash: "0x123" }); // replace with a real transaction hash
console.log("Is the transaction pending?", isPendingTransaction);
}
runExample().catch(console.error);
Generates a transaction to publish a Move package to the blockchain. This function helps you create a transaction that can be simulated or submitted to the chain for publishing a package.
To get the metadataBytes and byteCode, can compile using Aptos CLI with command
aptos move compile --save-metadata ...,
https://aptos.dev/tutorials/your-first-dapp/#step-4-publish-a-move-module
The arguments for publishing the package.
The publisher account.
The package metadata bytes.
An array of the bytecode of each module in the package in compiler output order.
Optionaloptions?: InputGenerateTransactionOptionsOptional settings for generating the transaction.
A SimpleTransaction that can be simulated or submitted to the chain.
import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
async function runExample() {
// Replace with a real account address
const account = "0x1";
const metadataBytes = "0x..."; // replace with real metadata bytes
const byteCode = "0x..."; // replace with real module bytecode
const transaction = await aptos.publishPackageTransaction({
account,
metadataBytes,
moduleBytecode: [byteCode],
});
console.log(transaction);
}
runExample().catch(console.error);
Rotates the authentication key for a given account. Once an account is rotated, only the new private key or keyless signing scheme can be used to sign transactions for the account.
The arguments for rotating the authentication key.
The account from which the authentication key will be rotated.
Optionaloptions?: InputGenerateTransactionOptions | undefinedOptionaldangerouslySkipVerification?: undefined(Optional) If true, skips verification steps after rotation. Required when using toAuthKey.
(Optional) The target account to rotate to. Required if not using toNewPrivateKey or toAuthKey.
OptionaldangerouslySkipVerification?: undefined(Optional) If true, skips verification steps after rotation. Required when using toAuthKey.
(Optional) The new private key to rotate to. Required if not using toAccount or toAuthKey.
(Optional) If true, skips verification steps after rotation. Required when using toAuthKey.
(Optional) The new authentication key to rotate to. Can only be used with dangerouslySkipVerification=true.
PendingTransactionResponse
This function supports three modes of rotation:
When not using dangerouslySkipVerification, the function performs additional safety checks and account setup.
If the new key is a multi key, skipping verification is dangerous because verification will publish the public key onchain and prevent users from being locked out of the account from loss of knowledge of one of the public keys.
import { Aptos, AptosConfig, Network, Account, PrivateKey } from "@aptos-labs/ts-sdk";
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
async function runExample() {
// Rotate the authentication key for an account
const response = await aptos.rotateAuthKey({
// replace with a real account
fromAccount: Account.generate(),
// replace with a real private key
toNewPrivateKey: new PrivateKey("0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"),
});
console.log(response);
}
runExample().catch(console.error);
Sign a transaction that can later be submitted to the chain. This function is essential for ensuring the authenticity of the transaction by using the provided account's signing capabilities.
The arguments for signing the transaction.
The account that will sign the transaction.
A raw transaction to sign.
AccountAuthenticator - The authenticator for the signed transaction.
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 sender = Account.generate(); // Generate a new account for signing
const transaction = await aptos.transaction.build.simple({
sender: sender.accountAddress,
data: {
function: "0x1::aptos_account::transfer",
functionArguments: [ "0x1", 100 ], // replace with a real account address and amount
},
});
const signedTransaction = await aptos.transaction.sign({
signer: sender,
transaction,
}); // Sign the transaction
console.log("Signed Transaction:", signedTransaction);
}
runExample().catch(console.error);
Sign and submit a single signer transaction as the fee payer to chain given an authenticator by the sender of the transaction.
The fee payer account to sign the transaction
The AccountAuthenticator signed by the sender of the transaction
An instance of a RawTransaction, plus optional secondary/fee payer addresses
PendingTransactionResponse
const transaction = await aptos.transaction.build.simple({sender: alice.accountAddress, feePayer: true ...})
const senderAuthenticator = alice.signTransactionWithAuthenticator(transaction)
const pendingTransaction = await aptos.signAndSubmitAsFeePayer({
senderAuthenticator,
feePayer: bob,
transaction,
})
Sign and submit a single signer transaction to the blockchain. This function allows you to execute a transaction after signing it with the specified account.
The arguments for signing and submitting the transaction.
The signer account to sign the transaction.
An instance of a RawTransaction, plus optional secondary/fee payer addresses.
PendingTransactionResponse
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 sender = Account.generate(); // Generate a new account for sending the transaction
const transaction = await aptos.transaction.build.simple({
sender: sender.accountAddress,
data: {
function: "0x1::aptos_account::transfer",
functionArguments: [ "0x1", 100 ], // replace with a real account address
},
});
// Sign and submit the transaction
const pendingTransaction = await aptos.signAndSubmitTransaction({
signer: sender,
transaction,
});
console.log(pendingTransaction);
}
runExample().catch(console.error);
Sign a transaction as a fee payer that can later be submitted to the chain. This function ensures that the transaction is marked with the fee payer's address, allowing it to be processed correctly.
The arguments for signing the transaction.
The fee payer signer account.
A raw transaction to sign on. This transaction must include a feePayerAddress property.
AccountAuthenticator - The authenticator for the signed transaction.
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 sender = Account.generate(); // Generate a new account for the fee payer
const transaction = await aptos.transaction.build.simple({
// All transactions on Aptos are implemented via smart contracts.
function: "0x1::aptos_account::transfer",
functionArguments: [sender.accountAddress, 100],
feePayerAddress: sender.accountAddress, // Set the fee payer address
});
const signedTransaction = await aptos.transaction.signAsFeePayer({
signer: sender,
transaction,
});
console.log("Signed transaction as fee payer:", signedTransaction);
}
runExample().catch(console.error);
Waits for a transaction to move past the pending state and provides the transaction response. There are 4 cases.
checkSuccess is true, the function will throw a FailedTransactionError
If checkSuccess is false, the function will resolve with the transaction response where the success field is false.args.options.timeoutSecs seconds.
Optionaloptions?: WaitForTransactionOptionsOptional parameters for waiting behavior.
The hash of a transaction previously submitted to the blockchain.
The transaction on-chain response.
import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
async function runExample() {
// Wait for a transaction to complete using its hash
const transactionHash = "0x123"; // replace with a real transaction hash
const transactionResponse = await aptos.waitForTransaction({
transactionHash,
options: {
timeoutSecs: 30, // specify your own timeout if needed
checkSuccess: true,
},
});
console.log(transactionResponse);
}
runExample().catch(console.error);
The main entry point for interacting with the Aptos APIs, providing access to various functionalities organized into distinct namespaces.
To utilize the SDK, instantiate a new Aptos object to gain access to the complete range of SDK features.
Example