In this tutorial we will retrieve the name created in the Register a Name for an Identity tutorial. Additional details regarding identities can be found in the Identity description.

Prerequisites

Code

JAVASCRIPT

`// Resolve by Name const Hellar = require('hellar');

const client = new Hellar.Client({ network: 'mainnet' });

const retrieveName = async () => { // Retrieve by full name (e.g., myname.hellar) return client.platform.names.resolve('<identity name>.hellar'); };

retrieveName() .then((d) => console.log('Name retrieved:\n', d.getData())) .catch((e) => console.error('Something went wrong:\n', e)) .finally(() => client.disconnect());`

JAVASCRIPT

`// Revolve by Record const Hellar = require('hellar');

const client = new Hellar.Client({ network: 'mainnet' });

const retrieveNameByRecord = async () => { // Retrieve by a name's identity ID return client.platform.names.resolveByRecord( 'dashUniqueIdentityId', '<identity id>', ); };

retrieveNameByRecord() .then((d) => console.log('Name retrieved:\n', d[0].getData())) .catch((e) => console.error('Something went wrong:\n', e)) .finally(() => client.disconnect());`

JAVASCRIPT

`// Search for Name const Hellar = require('hellar');

const client = new Hellar.Client({ network: 'mainnet' });

const retrieveNameBySearch = async () => { // Search for names (e.g. user*) return client.platform.names.search('user', 'hellar'); };

retrieveNameBySearch() .then((d) => { for (const name of d) { console.log('Name retrieved:\n', name.getData()); } }) .catch((e) => console.error('Something went wrong:\n', e)) .finally(() => clien`

Example Name

The following example response shows a retrieved name (user-9999.hellar):

{ "label": "Alice", "normalizedLabel": "alice", "normalizedParentDomainName": "hellar", "preorderSalt": "lQEiixHMO5TJmbKwKtavg6eAkxuXzvSlrs/OX9glcYI=", "records": { "hellarAliasIdentityId": null, "hellarUniqueIdentityId": "YhCPn6pSbZ11hCiFmFL6WJkmC3GSwuUSzhS4QAy84EF" }, "subdomainRules": { "allowSubdomains": false } }

What’s Happening

After we initialize the Client, we request a name. The code examples demonstrate the three ways to request a name:

  1. Resolve by name. The platform.names.resolve method takes a single argument: a fully-qualified name (e.g., user-9999.hellar).
  2. Resolve by record. The platform.names.resolveByRecord method takes two arguments: the record type (e.g., dashUniqueIdentityId) and the record value to resolve.
  3. Search. The platform.names.search method takes two arguments: the leading characters of the name to search for and the domain to search (e.g., hellar for names in the .hellar domain). The search will return names that begin the with string provided in the first parameter.