Name Resolver

Class Name NameResolver
Extends Logger
Source name-resolver.ts
Examples name-resolver.spec.ts

The NameResolver is a collection of helper functions, that can be used for ENS interaction. These include:

  • setting and getting ENS addresses
  • setting and getting ENS content flags, which is used when setting data in distributed file system, especially in case of setting a description for an ENS address

constructor

new NameResolver(options);

Creates a new NameResolver instance.

Parameters

  1. options - NameResolverOptions: options for NameResolver constructor.
    • config - any: configuration object for the NameResolver instance
    • executor - Executor: Executor instance
    • contractLoader - ContractLoader: ContractLoader instance
    • web3 - Web3: Web3 instance
    • log - Function (optional): function to use for logging: (message, level) => {...}
    • logLevel - LogLevel (optional): messages with this level will be logged with log
    • logLog - LogLogInterface (optional): container for collecting log messages
    • logLogLevel - LogLevel (optional): messages with this level will be pushed to logLog

Returns

NameResolver instance

Example

const nameResolver = new NameResolver({
    cryptoProvider,
    dfs,
    executor,
    keyProvider,
    nameResolver,
    contractLoader,
    web3,
  });

getAddressOrContent

nameResolver.getAddressOrContent(name, type);

get address or content of an ens entry

Parameters

  1. name - string: ens domain name (plain text)
  2. type - string: content type to get (address or content)

Returns

Promise resolves to string: address, returns null if not available

Example

const testEvanAddress = await runtime.nameResolver.getAddressOrContent('test.evan', 'address');
// returns 0x9c0Aaa728Daa085Dfe85D3C72eE1c1AdF425be49

getAddress

nameResolver.getAddress(name);

get address of an ens entry

Parameters

  1. name - string: ens domain name (plain text)

Returns

Promise resolves to string: address, returns null if not available

Example

const testEvanAddress = await runtime.nameResolver.getAddress('test.evan');
// returns 0x9c0Aaa728Daa085Dfe85D3C72eE1c1AdF425be49

getContent

nameResolver.getContent(name);

get content of an ens entry

Parameters

  1. name - string: ens domain name (plain text)

Returns

Promise resolves to string: content, returns null if not available

Example

const testEvanAddress = await runtime.nameResolver.getContent('test.evan');
// returns  (encoded ipfs hash) 0x9c0Aaa728Daa085Dfe85D3C72eE1c1AdF425be49

setAddressOrContent

nameResolver.setAddressOrContent(name, value, accountId, domainOwnerId, type);

set ens name. this can be a root level domain domain.test or a subdomain sub.domain.test

Parameters

  1. name - string: ens domain name (plain text)
  2. value - string: ethereum address
  3. accountId - string: owner of the parent domain
  4. domainOwnerId - string: owner of the address to set
  5. type - string: content type to set

Returns

Promise resolves to void: resolves when done

Example

const testEvanAddress = await runtime.nameResolver
  .setAddressOrContent(
    'test.evan',
    '0x9c0Aaa728Daa085Dfe85D3C72eE1c1AdF425be49',
    '0x000000000000000000000000000000000000beef',
    '0x000000000000000000000000000000000000beef',
    'address'
  );
// returns  (encoded ipfs hash) 0x9c0Aaa728Daa085Dfe85D3C72eE1c1AdF425be49

setAddress

nameResolver.setAddress(name, address, accountId, domainOwnerId);

set address for ens name. this can be a root level domain domain.test or a subdomain sub.domain.test

Parameters

  1. name - string: ens domain name (plain text)
  2. address - string: ethereum address
  3. accountId - string: owner of the parent domain
  4. domainOwnerId - string: owner of the address to set

Returns

Promise resolves to void: resolves when done

Example

const testEvanAddress = await runtime.nameResolver
  .setAddress(
    'test.evan',
    '0x9c0Aaa728Daa085Dfe85D3C72eE1c1AdF425be49',
    '0x000000000000000000000000000000000000beef',
    '0x000000000000000000000000000000000000beef'
  );

setContent

nameResolver.setContent(name, content, accountId, domainOwnerId);

set content for ens name. this can be a root level domain domain.test or a subdomain sub.domain.test

Parameters

  1. name - string: ens domain name (plain text)
  2. content - string: ethereum address
  3. accountId - string: owner of the parent domain
  4. domainOwnerId - string: owner of the address to set

Returns

Promise resolves to void: resolves when done

Example

const testEvanAddress = await runtime.nameResolver
  .setContent(
    'test.evan',
    '0x9c0Aaa728Daa085Dfe85D3C72eE1c1AdF425be49',
    '0x000000000000000000000000000000000000beef',
    '0x000000000000000000000000000000000000beef'
  );

claimAddress

nameResolver.claimAddress(name, executingAddress[, domainOwnerId, price]);

Tries to claim node ownership from parent nodes owner, this assumes, that the parent node owner is a registar, that supports claiming address from it (FIFS registrar or PayableRegistrar).

Parameters

  1. name - string: domain name to set (plain text)
  2. executingAddress - string: identity or account executing the transaction
  3. domainOwnerId - string (optional): owner of the new domain, defaults to executingAddress
  4. value - string|number (optional): value to send (if registrar is payable)

Returns

Promise returns void: resolved when done

Example

// claim '123test.fifs.registrar.test.evan' with identities[0] for identities[1] from FIFS registrar
const domain = '123test.fifs.registrar.test.evan';
await nameResolver.claimAddress(domain, identities[0], identities[1]);

// claim '123test.payable.registrar.test.evan' with identities[0] for identities[1] from payable registrar
const domain = '123test.fifs.registrar.test.evan';
const price = await nameResolver.getPrice(domain);
await nameResolver.claimAddress(domain, identities[0], identities[1], price);

claimPermanentAddress

nameResolver.claimPermanentAddress(name, executingAddress[, domainOwnerId]);

Registers a permanent domain via registrar, can only be done by registrar owner.

Parameters

  1. name - string: domain name to set (plain text)
  2. executingAddress - string: identity or account, that executes the transaction, has to be registrar owner
  3. domainOwnerId - string (optional): owner of the new domain, defaults to executingAddress

Returns

Promise returns void: resolved when done

Example

// claim '123sample.evan' with identities[0] for identities[1] from registrar
const domain = '123sample.evan';
await nameResolver.claimPermanentAddress(domain, identities[0], identities[1]);

setPrice

nameResolver.setPrice(name, executingAddress, newPrice);

Set price for a registrar at a domain.

Parameters

  1. name - string: ENS address of a domain owned by a registrar (e.g. ‘sample.payable.test.evan’)
  2. executingAddress - string: identity or account that performs the action (needs proper permisions for registrar)
  3. newPrice - number|string (optional): new price in Wei

Returns

Promise returns void: resolved when done

Example

await nameResolver.setPrice(
  'payable.registrar.test.evan',
  '0x1111111111111111111111111111111111111111',
  web3.utils.toWei('5', 'ether'),
);

getPrice

nameResolver.getPrice(name);

Get price for domain (if domain is payable).

Parameters

  1. name - string: a domain to check price for (e.g. ‘sample.payable.test.evan’)

Returns

Promise returns string: price in Wei

Example

console.log(await nameResolver.getPrice('payable.registrar.test.evan'));
// Output:
// 5000000000000000000

setValidUntil

nameResolver.setValidUntil(name, executingAddress, newPrice);

Set duration, that an address is valid; resolval stops after this, depending on configuration of the ENS an extra period, where owner is still available, can be granted; notice that this can only be done by parent owner of given domain.

Parameters

  1. name - string: ENS address of a domain owned by a registrar (e.g. ‘sample.payable.test.evan’)
  2. executingAddress - string: identity or account that performs the action; must be parent owner of given domain
  3. validUntil - number|string: js timestamp, when name resolution stops

Returns

Promise returns void: resolved when done

Example

await nameResolver.setValidUntil(
  'payable.registrar.test.evan',
  '0x1111111111111111111111111111111111111111',
  Date.now() + 60000,
);

getValidUntil

nameResolver.getValidUntil(name);

Get timestamp, when domain will stop resolval.

Parameters

  1. name - string: domain to get valid until for

Returns

Promise returns string: js timestamp, when resolver lookup will expire

Example

console.log(await nameResolver.getValidUntil('payable.registrar.test.evan'));
// Output:
// 1544630375417

claimFunds

namerResolver.claimFunds(name, executingAddress);

Verification funds for domain.

Parameters

  1. name - string: ENS address of a domain owned by a registrar (e.g. ‘sample.payable.test.evan’)
  2. executingAddress - string: identity or account that performs the action (needs proper permisions for registrar)

Returns

Promise returns void: resolved when done

Example

await nameResolver.claimFunds(
  'payable.registrar.test.evan',
  '0x1111111111111111111111111111111111111111',
);

getFactory

nameResolver.getFactory(contractName);

helper function for retrieving a factory address (e.g. ‘tasks.factory.evan’)

Parameters

  1. contractName - string: name of the contract that is created by the factory

Returns

string: address of the contract factory

Example

const taskFactory = await runtime.nameResolver.getFactory('tasks');
// returns '0x9c0Aaa728Daa085Dfe85D3C72eE1c1AdF425be49';

getDomainName

nameResolver.getDomainName(domainConfig, ...subLabels);

builds full domain name based on the provided domain config a module initalization.

Parameters

  1. domainConfig - string[] | string: The domain configuration
  2. ...subLabels - string[]: array of domain elements to be looked up and added at the lefthand

Returns

string: the domain name

Example

const domain = runtime.nameResolver.getDomainName(['factory', 'root'], 'task');
// returns 'task.factory.evan';

getArrayFromIndexContract

nameResolver.getArrayFromIndexContract(indexContract, listHash, retrievers, chain, triesLeft);

retrieve an array with all values of a list from an index contract.

Parameters

  1. indexContract - any: Ethereum contract address (DataStoreIndex)
  2. listHash - string: bytes32 namehash like api.nameResolver.sha3(‘ServiceContract’)
  3. retrievers - any (optional): overwrites for index or index like contract property retrievals defaults to:
{
  listEntryGet: 'listEntryGet',
  listLastModified: 'listLastModified',
  listLength: 'listLength',
}
  1. chain - Promise: Promise, for chaining multiple requests (should be omitted when called ‘from outside’, defaults to Promise.resolve())
  2. triesLeft - number: tries left before quitting defaults to 10

Returns

Promise resolves to string[]: list of addresses


getArrayFromListContract

nameResolver.getArrayFromListContract(indexContract, count, offset, reverse, chain, triesLeft);

retrieve an array with all values of a list from an index contract.

Parameters

  1. indexContract - any: Ethereum contract address (DataStoreIndex)
  2. count - number (optional): how many items should be returned, defaults to 10
  3. offset - number (optional): how many items should be skipped, defaults to 0
  4. reverse - boolean (optional): should the list be iterated reverse, defaults to false
  5. chain - Promise (optional): Promise, for chaining multiple requests (should be omitted when called ‘from outside’, defaults to Promise.resolve())
  6. triesLeft - number (optional): tries left before quitting defaults to 10

Returns

Promise resolves to string[]: list of addresses


getArrayFromUintMapping

nameResolver.getArrayFromUintMapping(contract, countRetriever, elementRetriever[, count, offset, reverse]);

retrieve elements from a contract using a count and element retriever function.

Parameters

  1. contract - any: Ethereum contract address (DataStoreIndex)
  2. countRetriever - Function : function which returns the count of the retrieved elements
  3. elementRetriever - Function : function which returns the element of the retrieved elements
  4. count - number (optional): number of elements to retrieve, defaults to 10
  5. offset - number (optional): skip this many items when retrieving, defaults to 0
  6. reverse - boolean (optional): retrieve items in reverse order, defaults to false

Returns

Promise resolves to string[]: list of addresses


sha3

nameResolver.sha3(input);

sha3 hashes an input, substitutes web3.utils.sha3 from geth console

Parameters

  1. input - string | buffer: input text or buffer to hash

Returns

string: hashed output


soliditySha3

nameResolver.soliditySha3(...args);

Will calculate the sha3 of given input parameters in the same way solidity would. This means arguments will be ABI converted and tightly packed before being hashed.

Parameters

  1. args - string | buffer: arguments for hashing

Returns

string: hashed output


namehash

nameResolver.namehash(inputName);

hash ens name for usage in contracts

Parameters

  1. inputName - string: inputName ens name to hash

Returns

string: name hash


bytes32ToAddress

nameResolver.bytes32ToAddress(hash);

converts a bytes32 hash to address

Parameters

  1. hash - string: bytes32 hash

Returns

string: converted address