Tezos Domains for Developers #1: Resolving Domains

Tezos Domains for Developers #1: Resolving Domains

As part of our journey to bring Tezos Domains to mainnet, we are preparing a series of short articles covering how-tos and examples of integration. Our aim is to make the experience easier for developers starting with Tezos Domain.

All of the code in the series can be found in our dedicated repository. It contains the latest versions of our examples and includes instructions for running them.

Introducing Tezos Domains Client

We’ve prepared Typescript/Javascript packages that cover a range of integration options. They are built on top of the Taquito suite.

You can start by installing the required packages with your package manager of choice:

npm install @tezos-domains/client @tezos-domains/core @taquito/taquito

A basic typescript file that will get us started looks like this:

import { TezosToolkit } from '@taquito/taquito';
import { TezosDomainsClient } from '@tezos-domains/client';

(async () => {
    const tezos = new TezosToolkit('https://delphinet-tezos.giganode.io/');
    const client = new TezosDomainsClient({ tezos, network: 'delphinet' });

    // ...

})().catch(e => console.error(e));

You can see it defines an instance of TezosDomainsClient connected to Delphinet, that we can later use.

Resolving a Domain

NameResolver takes care of resolving domains to addresses and vice versa. It automatically handles all the necessary steps (like filtering out expired domains). You can get an instance from the client and use it to resolve an address:

const address = await client.resolver.resolveNameToAddress('bob.delphi');
console.log(address);

Running the example gives us the expected output of tz1NjFgwjd7k1TJXLrzHjqS1TAFeiGCVVSLS.

Tezos Domains will keep track of more information though. A full domain record includes an owner (the account with the permission to make changes), its expiration date, and any arbitrary data associated with the domain.

const record = await client.resolver.resolveDomainRecord('bob.delphi');
console.log(record);

This will give us the complete record:

{
  address: 'tz1NjFgwjd7k1TJXLrzHjqS1TAFeiGCVVSLS',
  data: RecordMetadata {
    data: {
      'openid:email': '22626f624076616e63652d72656672696765726174696f6e2e636f6d22',
      'openid:name': '22426f622056616e636522'
    }
  },
  owner: 'tz1NjFgwjd7k1TJXLrzHjqS1TAFeiGCVVSLS',
  level: 2,
  expiry: 2025-10-28T17:13:27.000Z
}                                                

Data is a map of values that users can associate with every record. In this example, the data consist of two OpenID claims. To get a javascript representation instead of bytes (22626f...), we can use the getJson() method:

console.log(record.data.getJson('openid:name'));
console.log(record.data.getJson('openid:email'));

This prints out:

bob@vance-refrigeration.com
Bob Vance                  

The full source code is available in resolve-domain.ts.

Resolving an Address to a Domain (Reverse Resolution)

Tezos Domains also allow for reverse lookups. This means that we can resolve an address back to a domain. Reverse resolution is guaranteed to be consistent, i.e. an address X can only resolve to alice.tez if alice.tez resolves to X. The opposite is not true however: reverse records are optional.

We can perform a reverse lookup and print out the domain this address resolves to.

const address = await client.resolver.resolveAddressToName('tz1NjFgwjd7k1TJXLrzHjqS1TAFeiGCVVSLS');
console.log(address);

Again, a full record can be resolved as well:

const record = await client.resolver.resolveReverseRecord('tz1NjFgwjd7k1TJXLrzHjqS1TAFeiGCVVSLS');
console.log(record);

Resulting in:

{
  name: 'bob.delphi',
  owner: 'tz1NjFgwjd7k1TJXLrzHjqS1TAFeiGCVVSLS',
  data: RecordMetadata { data: {} }
}

The full source code is available in resolve-reverse-record.ts.

About the Team

The team at Agile Ventures has been working with Tezos since the early alphanet days. We have created two open-sourced projects focused on helping developers interact with the Tezos data and events easier and are hosting publicly available endpoints at TezosLive.io. Nowadays, we mostly focus on Tezos Domains.

7 Likes

Bob vance, that’s the coolest part.

1 Like