Library for resolving and managing tezos domains. Can be used with Taquito or ConseilJS.
WARNING: This project is in beta. We welcome users and feedback, please be aware that this project is a work in progress.
@tezos-domains/taquito-client packageyarn add @tezos-domains/taquito-client @tezos-domains/core @taquito/taquito @taquito/rpc @taquito/tzip16
--or--
npm install @tezos-domains/taquito-client @tezos-domains/core @taquito/taquito @taquito/rpc @taquito/tzip16
The resolver uses TZIP-16 off-chain views, whose code Taquito loads from the NameRegistry contract metadata on IPFS. Tzip16Module without arguments loads it through ipfs.io, whose public gateway no longer serves this content reliably, so name resolution fails. Configure a gateway that works, and fall back across several so a single outage does not take name resolution down:
import { ContractAbstraction, ContractProvider, Context, Wallet } from '@taquito/taquito';
import { DEFAULT_HANDLERS, Handler, IpfsHttpHandler, MetadataProvider, Tzip16Uri } from '@taquito/tzip16';
// Tries each gateway in order and returns the first answer.
export class FallbackIpfsHandler implements Handler {
constructor(private handlers: Handler[]) {}
async getMetadata(contract: ContractAbstraction<ContractProvider | Wallet>, uri: Tzip16Uri, context: Context): Promise<string> {
let lastError: unknown = new Error('No IPFS gateway configured.');
for (const handler of this.handlers) {
try {
return await handler.getMetadata(contract, uri, context);
} catch (error) {
lastError = error;
}
}
throw lastError;
}
}
export function createMetadataProvider(): MetadataProvider {
const handlers = new Map(DEFAULT_HANDLERS);
const gateways = ['ipfs.filebase.io', 'gateway.pinata.cloud', '4everland.io'];
handlers.set('ipfs', new FallbackIpfsHandler(gateways.map(gateway => new IpfsHttpHandler(gateway))));
return new MetadataProvider(handlers);
}
In production, prefer a gateway you control or pay for as the first entry. The metadata is content-addressed, so every gateway that can retrieve it returns identical bytes: the choice is about availability and latency, not trust.
The examples below use createMetadataProvider() from this step.
resolver to resolve names and addressesExample of resolving and address from domain name:
import { TezosToolkit } from '@taquito/taquito';
import { TaquitoTezosDomainsClient } from '@tezos-domains/taquito-client';
import { Tzip16Module } from '@taquito/tzip16';
async function main() {
const tezos = new TezosToolkit('https://ghostnet.smartpy.io');
tezos.addExtension(new Tzip16Module(createMetadataProvider()));
const client = new TaquitoTezosDomainsClient({ tezos, network: 'ghostnet', caching: { enabled: true } });
const address = await client.resolver.resolveNameToAddress('bob.flo');
console.log(address);
}
manager to register and manage domainsExample of registering a domain:
NOTE: registering a domain uses commitment scheme.
NOTE: Installing a signer is necessary for sending transactions.
yarn add @taquito/signer
--or--
npm install @taquito/signer
import { InMemorySigner } from '@taquito/signer';
import { TezosToolkit } from '@taquito/taquito';
import { Tzip16Module } from '@taquito/tzip16';
import { TaquitoTezosDomainsClient } from '@tezos-domains/taquito-client';
import { getTld, getLabel, DomainNameValidationResult, RecordMetadata, generateNonce } from '@tezos-domains/core';
async function main() {
const tezos = new TezosToolkit('https://ghostnet.smartpy.io');
tezos.addExtension(new Tzip16Module(createMetadataProvider()));
tezos.setSignerProvider(new InMemorySigner('<your signing key>'));
const client = new TaquitoTezosDomainsClient({ tezos, network: 'ghostnet' });
const name = 'foobar.flo';
// Validate the domain name syntax
if (client.validator.validateDomainName(name) !== DomainNameValidationResult.VALID) {
throw new Error('Domain name not valid');
}
// Check if the name is not taken already
const existing = await client.resolver.resolveDomainRecord(name);
if (existing) {
throw new Error('Domain name taken.');
}
// Use utility function to parse and get parts of a domain name
const tld = getTld(name);
const label = getLabel(name);
const nonce = generateNonce();
const params = {
label,
owner: 'tz1VxMudmADssPp6FPDGRsvJXE41DD6i9g6n',
nonce
};
// First step of registering a domain - create a commitment for
const commitOperation = await client.manager.commit(tld, params);
await commitOperation.confirmation();
// Wait until commitment is usable (usually time between blocks)
const commitment = await client.manager.getCommitment(tld, params);
await commitment.waitUntilUsable();
// Final step - reveal and confirm the registration for specified duration in days
const buyOperation = await client.manager.buy(tld, {
...params,
duration: 365,
address: 'tz1VxMudmADssPp6FPDGRsvJXE41DD6i9g6n',
data: new RecordMetadata(),
});
await buyOperation.confirmation();
console.log(`Domain ${name} has been registered.`);
}
@tezos-domains/conseil-client packageyarn add @tezos-domains/conseil-client @tezos-domains/core conseiljs node-fetch loglevel @types/node-fetch @types/loglevel
--or--
npm install @tezos-domains/conseil-client @tezos-domains/core conseiljs node-fetch loglevel @types/node-fetch @types/loglevel
resolver to resolve names and addressesExample of resolving and address from domain name:
import fetch from 'node-fetch';
import * as log from 'loglevel';
import { registerFetch, registerLogger } from 'conseiljs';
import { ConseilTezosDomainsClient } from '@tezos-domains/conseil-client';
async function main() {
const logger = log.getLogger('conseiljs');
logger.setLevel('silent', false);
registerLogger(logger);
registerFetch(fetch);
const client = new ConseilTezosDomainsClient({
conseil: { server: 'https://ghostnet.smartpy.io' },
network: 'ghostnet',
caching: { enabled: true },
});
const address = await client.resolver.resolveNameToAddress('bob.flo');
console.log(address);
}
The client takes options that can customize it's behavior.
network (default: 'mainnet')
mainnet and ghostnet. For custom you need to also specify contractAddresses.contractAddresses (default: undefined)
custom. Uses built in addresses otherwise.tlds (default: undefined)
custom. Uses built in tlds otherwise.tracing (default: false)
caching (default { enabled: false, defaultRecordTtl: 600, defaultReverseRecordTtl: 600 })
tezos (required)
conseil (required)
server Specifies tezos rpc url to make requests to.This project requires Yarn.
yarn install
yarn build
yarn test