Integrate ANS into dApp

The API service provided by aleo-name-service-api. We recommend that developers run their own Indexer, but developers can use the official ANS Indexer service for development and testing during the development phase.

Query the primary name of an address

Check if an address has set a primary domain name. A 404 response means it has not been configured.

// Replace "aleo1s......abcdef" with the address you want to lookup.
const address = "aleo1s......abcdef";
const response = await fetch(`${address}`);
const { name } = await response.json();

Convert ANS name to address

Check if a domain name has a corresponding address. A 404 response indicates that it has not been registered. If the returned address is not an Aleo address, it means the domain is privately registered and not publicly disclosed.

// Replace "test.ans" with your ANS name. 
// For private name, the address will be "Private Registration".
const name = "test.ans";
const response = await fetch(`${name}`);
const { address } = await response.json();

Convert ANS name_hash to Human-readable Name

Convert an ANS name_hash to its human-readable name. A 404 response indicates that the name has not been registered. The returned data includes a balance field, which represents the ACs (Aleo Credits) received by this ANS without a set password. Users can withdraw these ACs as needed.

// Replace "2161886410952211525886505790676792679800209349697935268316503861742165891860field" with your ANS name_hash. 
const name_hash = "2161886410952211525886505790676792679800209349697935268316503861742165891860field";
const response = await fetch(`${name_hash}`);
const { name, balance } = await response.json();

Query resolver content

Query a domain name's configured resolver content. A 404 response indicates it has not been set up. If configured

// Replace "test.ans" with your ANS name. replace category with category you want to lookup.
const name = "test.ans";
const category = "btc";
const response = await fetch(`${name}&category=${category}`);
const { content } = await response.json();

Query avatar

The avatar falls under a resolver category. To retrieve a domain name's assigned avatar, specify category="avatar". If an avatar has been set up, the 'content' will point to the avatar image hosted on IPFS.

Last updated