Docs
Integrate Aptos Name Service into your app in 3 lines of Javascript.
Rest API
Convert a name to an address.
1 2 3 4 // Replace "test" with your ANS name. Remember to remove ".aptos" from the name. const name = "test"; const response = await fetch(`https://www.aptosnames.com/api/v1/address/${name}`); const { address } = await response.json();

Convert an address to its name.
1 2 3 4 // Replace "address" with the address you want to lookup. const address = "0x1234...abcdef"; const response = await fetch(`https://www.aptosnames.com/api/v1/name/${address}`); const { name } = await response.json();

On-chain API
These examples use the Aptos npm package.
yarn add aptos

Convert a name to an address.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 import { AptosClient } from "aptos"; const aptosClient = new AptosClient("https://fullnode.devnet.aptoslabs.com"); // Replace "test" with your ANS name. Remember to remove ".aptos" from the name. const name = "test"; const address = await aptosClient.getTableItem( // Current devnet handle. Updates every time devnet resets. "0x5de678e77f5106bb91cbf0960bcc023d03f2c56d4b1552631dea9effe757b6a7", { key_type: "0x1::string::String", value_type: "address", key: name } );

Convert an address to its name.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 import { AptosClient } from "aptos"; const aptosClient = new AptosClient("https://fullnode.devnet.aptoslabs.com"); // Replace "address" with the address you want to lookup. const address = "0x1234...abcdef"; const name = await aptosClient.getTableItem( // Current devnet handle. Updates every time devnet resets. "0x4109f6651aab3abdb98a64fa7ede37bb164d0cbccea585dc76e10874e54d0145", { key_type: "address", value_type: "0x1::string::String", key: address } );