Edit this page

Reverse Resolve Domains Using Smart Contracts

This guide covers how to retrieve the reverse record of UD domains using smart contracts. This process requires using the ABIs built into the Unstoppable Domains UNS smart contract.

Step 1: Select a UNS Registry Smart Contract

The UNS Registry smart contract is where domain owners store their data and is a map of domain namehashes to key-value dictionaries of records. Choose one of the Unstoppable Registry smart contracts to interact with (either mainnet or testnet).

polygon registry contract

polygon registry contract

Step 2: Open the “Read as Proxy” Tab for the Registry Contract

Navigate to the Contract tab in either the Etherscan or Polygonscan page of the Registry contract and click on the Read as Proxy tab:

polygonscan read as proxy tab

polygonscan read as proxy tab

Step 3: Retrieve the Reverse Record

The UNS contract has a reverseNameOf() method that takes in a wallet address and returns the name of the domain that has configured Reverse Resolution to that address.

polygonscan reverseNameOf method

polygonscan reverseNameOf method

Add the wallet address you want to resolve in the addr field of the reverseNameOf() method and click the Query button.

polygonscan reverseNameOf response

polygonscan reverseNameOf response
info

The reverseNameOf() method will return a value of '' if there is no reverse record configured for the wallet address provided.

reverseNameOf() method will return human-readable domain name.

To calculate namehash from domain name use namehashing functions:

You can generate the namehash of a domain using any of the Resolution Libraries, Resolution CLI, or Resolution Service. You can also use online tools to calculate the namehash of the domain.

JavaScriptJavaSwiftGolangResolution CLI
Copy
Copied
const {default: Resolution} = require('@unstoppabledomains/resolution');
// obtain a key by following this document https://docs.unstoppabledomains.com/domain-distribution-and-management/quickstart/retrieve-an-api-key/#api-key
const resolution = new Resolution({ apiKey: "<api_key>" });
let namehash = resolution.namehash("brad.crypto", "UNS");
Copy
Copied
import com.unstoppabledomains.resolution.Resolution;
// obtain a key by following this document https://docs.unstoppabledomains.com/domain-distribution-and-management/quickstart/retrieve-an-api-key/#api-key. See https://github.com/unstoppabledomains/resolution-java for more initialization options
DomainResolution resolution = new Resolution("<api_key>");
String namehash = resolution.getNamehash("brad.crypto", "UNS");
Copy
Copied
import UnstoppableDomainsResolution

// obtain a key by following this document https://docs.unstoppabledomains.com/domain-distribution-and-management/quickstart/retrieve-an-api-key/#api-key. See https://github.com/unstoppabledomains/resolution-swift for more initialization options
guard let resolution = try? Resolution(apiKey: "<api_key>") else {
  print ("Init of Resolution instance failed...")
  return
}

let namehash = try resolution.namehash(domain: "brad.crypto")
Copy
Copied
package main

import (
    "fmt"
    "github.com/unstoppabledomains/resolution-go/v3"
)

func main() {
    // obtain a key by following this document https://docs.unstoppabledomains.com/domain-distribution-and-management/quickstart/retrieve-an-api-key/#api-key. See https://github.com/unstoppabledomains/resolution-go for more initialization options
    uns, _ := resolution.NewUnsBuilder().SetUdClient("<api_key>").Build()
    namehash, _ := uns.Namehash("brad.crypto")
    fmt.Println("The namehash for brad.crypto is", namehash)
}
Copy
Copied
$ resolution namehash -d brad.crypto
"0x756e4e998dbffd803c21d23b06cd855cdc7a4b57706c95964a37e24b47c10fc9"
info

The JavaScript and Java Resolution Libraries require a Naming Service parameter to generate namehashes. This specifies the name service that manages the domain name, and the value must either be "UNS" or "ZNS".

Smart Contract Considerations

Integrating Reverse Resolution with smart contracts involves using the reverseNameOf() method to retrieve the domain name of the reverse record.

You can also integrate Reverse Resolution into your application using libraries that allow you to call smart contracts ABIs like ethers.js and web3.js. Here’s an application that integrates Reverse Resolution using ethers.js: https://github.com/Noxturnix/web3udmintfeed.nft.

An example in JavaScript of integrating Reverse Resolution (using the ethers.js library):

Copy
Copied
const proxyReaderAddress = "0x423F2531bd5d3C3D4EF7C318c2D1d9BEDE67c680";

// partial ABI, just for the reverseNameOf method
const proxyReaderAbi = [
    "function reverseNameOf(address addr) external view returns (string)",
];

const proxyReaderContract = new ethers.Contract(
    proxyReaderAddress,
    proxyReaderAbi,
    provider
);

const address = "0x88bc9b6c56743a38223335fac05825d9355e9f83";

// call the reverseNameOf method
const reverseDomainName = await proxyReaderContract.reverseNameOf(address);
// jim-unstoppable.x
Congratulations

You have successfully integrated Reverse Resolution using smart contracts. Happy Hacking!