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¶
- options-- NameResolverOptions: options for NameResolver constructor.
- config-- any: configuration object for the NameResolver instance
- executor-- Executor:- Executorinstance
- contractLoader-- ContractLoader:- ContractLoaderinstance
- web3-- Web3:- Web3instance
- 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¶
- name-- string: ens domain name (plain text)
- 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¶
- 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¶
- 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¶
- name-- string: ens domain name (plain text)
- value-- string: ethereum address
- accountId-- string: owner of the parent domain
- domainOwnerId-- string: owner of the address to set
- 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¶
- name-- string: ens domain name (plain text)
- address-- string: ethereum address
- accountId-- string: owner of the parent domain
- 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¶
- name-- string: ens domain name (plain text)
- content-- string: ethereum address
- accountId-- string: owner of the parent domain
- 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'
  );
getFactory¶
nameResolver.getFactory(contractName);
helper function for retrieving a factory address (e.g. ‘tasks.factory.evan’)
Parameters¶
- 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¶
- domainConfig-- string[] | string: The domain configuration
- ...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¶
- indexContract-- any: Ethereum contract address (DataStoreIndex)
- listHash-- string: bytes32 namehash like api.nameResolver.sha3(‘ServiceContract’)
- retrievers-- any(optional): overwrites for index or index like contract property retrievals defaults to:
{
  listEntryGet: 'listEntryGet',
  listLastModified: 'listLastModified',
  listLength: 'listLength',
}
- chain-- Promise: Promise, for chaining multiple requests (should be omitted when called ‘from outside’, defaults to Promise.resolve())
- triesLeft-- number: tries left before quitting defaults to- 10
getArrayFromListContract¶
nameResolver.getArrayFromListContract(indexContract, count, offset, reverse, chain, triesLeft);
retrieve an array with all values of a list from an index contract.
Parameters¶
- indexContract-- any: Ethereum contract address (DataStoreIndex)
- count-- number(optional): how many items should be returned, defaults to- 10
- offset-- number(optional): how many items should be skipped, defaults to- 0
- reverse-- boolean(optional): should the list be iterated reverse, defaults to- false
- chain-- Promise(optional): Promise, for chaining multiple requests (should be omitted when called ‘from outside’, defaults to Promise.resolve())
- triesLeft-- number(optional): tries left before quitting defaults to- 10
getArrayFromUintMapping¶
nameResolver.getArrayFromUintMapping(contract, countRetriever, elementRetriever[, count, offset, reverse]);
retrieve elements from a contract using a count and element retriever function.
Parameters¶
- contract-- any: Ethereum contract address (DataStoreIndex)
- countRetriever-- Function: function which returns the count of the retrieved elements
- elementRetriever-- Function: function which returns the element of the retrieved elements
- count-- number(optional): number of elements to retrieve, defaults to- 10
- offset-- number(optional): skip this many items when retrieving, defaults to- 0
- reverse-- boolean(optional): retrieve items in reverse order, defaults to- false
sha3¶
nameResolver.sha3(input);
sha3 hashes an input, substitutes web3.utils.sha3 from geth console
Parameters¶
- input-- string | buffer: input text or buffer to hash
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¶
- args-- string | buffer: arguments for hashing