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 instanceexecutor
-Executor
:Executor
instancecontractLoader
-ContractLoader
:ContractLoader
instanceweb3
-Web3
:Web3
instancelog
-Function
(optional): function to use for logging:(message, level) => {...}
logLevel
-LogLevel
(optional): messages with this level will be logged withlog
logLog
-LogLogInterface
(optional): container for collecting log messageslogLogLevel
-LogLevel
(optional): messages with this level will be pushed tologLog
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 addressaccountId
-string
: owner of the parent domaindomainOwnerId
-string
: owner of the address to settype
-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 addressaccountId
-string
: owner of the parent domaindomainOwnerId
-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 addressaccountId
-string
: owner of the parent domaindomainOwnerId
-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, accountId[, 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¶
name
-string
: domain name to set (plain text)accountId
-string
: account, that executes the transactiondomainOwnerId
-string
(optional): owner of the new domain, defaults toaccountId
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 account[0] for account[1] from FIFS registrar
const domain = '123test.fifs.registrar.test.evan';
await nameResolver.claimAddress(domain, accounts[0], accounts[1]);
// claim '123test.payable.registrar.test.evan' with account[0] for account[1] from payable registrar
const domain = '123test.fifs.registrar.test.evan';
const price = await nameResolver.getPrice(domain);
await nameResolver.claimAddress(domain, accounts[0], accounts[1], price);
claimPermanentAddress¶
nameResolver.claimPermanentAddress(name, accountId[, domainOwnerId]);
Registers a permanent domain via registrar, can only be done by registrar owner.
Parameters¶
name
-string
: domain name to set (plain text)accountId
-string
: account, that executes the transaction, has to be registrar ownerdomainOwnerId
-string
(optional): owner of the new domain, defaults toaccountId
Returns¶
Promise
returns void
: resolved when done
Example¶
// claim '123sample.evan' with account[0] for account[1] from registrar
const domain = '123sample.evan';
await nameResolver.claimPermanentAddress(domain, accounts[0], accounts[1]);
setPrice¶
nameResolver.setPrice(name, accountId, newPrice);
Set price for a registrar at a domain.
Parameters¶
name
-string
: ENS address of a domain owned by a registrar (e.g. ‘sample.payable.test.evan’)accountId
-string
: account that performs the action (needs proper permisions for registrar)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¶
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, accountId, 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¶
name
-string
: ENS address of a domain owned by a registrar (e.g. ‘sample.payable.test.evan’)accountId
-string
: account that performs the action; must be parent owner of given domainvalidUntil
-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¶
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, accountId);
Verification funds for domain.
Parameters¶
name
-string
: ENS address of a domain owned by a registrar (e.g. ‘sample.payable.test.evan’)accountId
-string
: 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¶
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 to10
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 to10
offset
-number
(optional): how many items should be skipped, defaults to0
reverse
-boolean
(optional): should the list be iterated reverse, defaults tofalse
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 to10
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 elementselementRetriever
-Function
: function which returns the element of the retrieved elementscount
-number
(optional): number of elements to retrieve, defaults to10
offset
-number
(optional): skip this many items when retrieving, defaults to0
reverse
-boolean
(optional): retrieve items in reverse order, defaults tofalse
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