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
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://limanet.smartpy.io');
tezos.addExtension(new Tzip16Module());
const client = new TaquitoTezosDomainsClient({ tezos, network: 'limanet', 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://limanet.smartpy.io');
tezos.addExtension(new Tzip16Module());
tezos.setSignerProvider(new InMemorySigner('<your signing key>'));
const client = new TaquitoTezosDomainsClient({ tezos, network: 'limanet' });
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://limanet.smartpy.io' },
network: 'limanet',
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 limanet
. 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 build
yarn test
Generated using TypeDoc