Reverse address resolution
Finding the domain associated with an address consists of X steps:
-
Obtain the identifier of the address reverse records.
Generate the RNS domain for a given account's reverse records. Convert the address to hexadecimal representation in lower-case, and append
addr.reverse
. For instance, the address0x112234455c3a32fd11230c42e7bccd4a84e02010
might have its reverse records associated at112234455c3a32fd11230c42e7bccd4a84e02010.addr.reverse
.Use
namehash
algorithm with the reverse record domain to get the identifier of the address. -
Get its resolver contract.
-
Detect if contract supports
name(bytes32)
interface via ERC-165 interface detection.Use
supportsInterface(bytes4)
with interface ID:0x691f3431
-
Query for name resolution.
Use
name(bytes32)
with the domain identifier.
function reverseResolve (address) {
const reverseName = `${address.slice(2).toLowerCase()}.addr.reverse`;
const node = namehash(reverseName);
const resolver = rns.resolver(node);
const name = resolver.name(node);
return name;
}
function getName(address) {
const reverseDomain = `${address.slice(2).toLowerCase()}.addr.reverse`;
const node = namehash(reverseDomain)
const resolver = rns.resolver(node)
if (!resolver.supportsInterface('0x691f3431'))
throw;
return resolver.name(node);
}