Guides
Dash CoreDash PlatformDash.orgDash User DocsLog In
Guides
These docs are for v0.14.0. Click to read the latest docs for v0.25-redirect.

Retrieve a Name

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.

Code

const Dash = require('dash');

const clientOpts = {
  network: 'evonet'
};

const client = new Dash.Client(clientOpts);

const retrieveName = async function () {
  try {
    const platform = client.platform;
    
    // Retrieve by full name (e.g., myname.dash)
    const name = await platform.names.resolve('<identity name>.dash');
    console.log(name.toJSON());
  } catch (e) {
    console.error('Something went wrong:', e);
  } finally {
    client.disconnect();
  }
}

retrieveName();
const Dash = require('dash');

const clientOpts = {
  network: 'evonet'
};

const client = new Dash.Client(clientOpts);

const retrieveName = async function () {
  try {
    const platform = client.platform;
    
    // Retrieve by a name's identity ID
    const nameFromId = await platform.names.resolveByRecord(
      'dashIdentity', 
      'A6HXEEeNkaRwg2qk7rpMJK7JTMH9f7idKyjKzqaB4Jix'
    );
    console.log(nameFromId.toJSON());   
  } catch (e) {
    console.error('Something went wrong:', e);
  } finally {
    client.disconnect();
  }
}

retrieveName();
const Dash = require('dash');

const clientOpts = {
  network: 'evonet'
};

const client = new Dash.Client(clientOpts);

const retrieveName = async function () {
  try {
    const platform = client.platform;
    
    // Search for names
    const nameSearch = await platform.names.search('user', 'dash');
    console.dir(nameSearch);
  } catch (e) {
    console.error('Something went wrong:', e);
  } finally {
    client.disconnect();
  }
}

retrieveName();

Example Name

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

{
  '$id': 'DnynB7mmAUQDz8JPg84KupmnwSjHKWhH2Gc6L9SwVXSH',
  '$type': 'domain',
  '$dataContractId': 'FiBkhut4LFPMJqDWbZrxVeT6Mr6LsH3mTNTSSHJY2ape',
  '$ownerId': 'A6HXEEeNkaRwg2qk7rpMJK7JTMH9f7idKyjKzqaB4Jix',
  '$revision': 1,
  label: 'user-9999',
  records: { dashIdentity: 'A6HXEEeNkaRwg2qk7rpMJK7JTMH9f7idKyjKzqaB4Jix' },
  nameHash: '5620054ce37002aac00ec6f2cc72b0f9a604f7b1e2a51338db655fef5b3ca5f503ef',
  preorderSalt: 'yddt5AzHL3VDjoMWqrfbahokyiqtzxXePN',
  normalizedLabel: 'user-9999',
  normalizedParentDomainName: 'dash'
}

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.dash).
  2. Resolve by record. The platform.names.resolveByRecord method takes two arguments: the record type (e.g., dashIdentity) 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., dash for names in the *.dash domain). The search will return names that begin the with string provided in the first parameter.

After the name is retrieved, it is displayed on the console.