Edit this page

Resolution-Java

This page details basic installation, configuration, and usage of the Java Resolution Library.

Installation

Resolution Java can be installed with using the JitPack package repository.

Initialize with Unstoppable Domains' Proxy Provider

Copy
Copied
DomainResolution resolution = Resolution
  .builder()
  // obtain a key by following this document https://docs.unstoppabledomains.com/domain-distribution-and-management/quickstart/retrieve-an-api-key/#api-key
  .udUnsClient("<api_key>")
  .znsProviderUrl("https://api.zilliqa.com")
  .build();

Initialize with Custom Ethereum Configuration

Configuration

The Resolution libraries require a connection to the Ethereum network to resolve domains (.crypto, .nft, etc.). To use these libraries, you must specify an Ethereum node service provider. Once you have created an instance of the library, you can begin resolving domains. Examples of how to initialize the library with different providers are provided below.

Provider URL

Each of the Resolution Libraries supports using an Ethereum provider URL for configuration. You can obtain this URL from a service like Alchemy, which offers a free API key to users who create an account. If you wish to use an alternative Ethereum provider, see the Nodes as a Service guide for more information.

Copy
Copied
import com.unstoppabledomains.resolution.Resolution;

// obtain a key from https://www.infura.io
String ethProviderURL = "https://mainnet.infura.io/v3/<infura_api_key>";
String polygonProviderURL = "https://polygon-mainnet.infura.io/v3/<infura_api_key>";

DomainResolution resolution = Resolution.builder()
  .unsProviderUrl(UNSLocation.Layer1, ethProviderURL)
  .unsProviderUrl(UNSLocation.Layer2, polygonProviderURL)
  .znsProviderUrl("https://api.zilliqa.com")
  .build();
warning

Make sure to allow eth-mainnet.g.alchemy.com and polygon-mainnet.g.alchemy.com or simply https://*.g.alchemy.com (if using the default configuration) as a connect-src in your Content Security Policy to allow these requests through.

Error Handling

Unstoppable Domains follows the error handling best practices specific to each library's language. Each error data structure contains an error code, a human-readable message, and extra details that may help you debug the error.

Copy
Copied
{
  code: string; // one of our custom error codes
  message?: string; // human-readable error summary
  providerMessage?: string; // internal error message from the provider (alchemy, infura, etc.)
  errorMessage?: string; // internal error message / nested error
  method?: ResolutionMethod; // resolution method (UNS L1, UNS L2, CNS, ZNS, UD API)
  methodName?: string; // resolution method that was used (e.g. Resolution.addr, Resolution.allRecords)
  domain?: string; // domain that caused the error
  currencyTicker?: string; // currency ticker that caused the error
  recordName?: string; // record that caused the error
  namingService?: string; // naming service (UNSL1, UNSL2, ZNS, ENS, CNS, etc.)
  location?: UnsLocation; // domain location (L1, L2)
  tokenUri?: string; // domain metadata link
}

The code snippet below shows how to handle the common error cases you may encounter during integration, including:

  • Resolving an unregistered domain
  • Resolving an undefined record of a domain
  • Resolving a misconfigured domain
  • Resolving a domain with an unsupported domain ending

We handle the errors thrown by the resolution library by switching on the error code and displaying custom messages to the user. You can then perform other actions to handle the error or show the error message value from the error data structure to the user.

Copy
Copied
import com.unstoppabledomains.resolution.Resolution;
import com.unstoppabledomains.exceptions.ns.NamingServiceException;
import com.unstoppabledomains.exceptions.ns.NSExceptionCode;

DomainResolution resolution = Resolution
  .builder()
  .udUnsClient("<api_key>")
try {
    String receiverETHAddress = resolution.getAddress("domain-with-error.crypto", "ETH");
} catch (NamingServiceException exception) {
   if (exception.getCode() == NSExceptionCode.UnregisteredDomain) {
        // Domain is not registered
   }
   if (exception.getCode() == NSExceptionCode.RecordNotFound) {
        // Crypto record is not found (or empty)
   }
   if (exception.getCode() == NSExceptionCode.UnspecifiedResolver) {
        // Domain is not configured (empty resolver)
   }
   if (exception.getCode() == NSExceptionCode.UnsupportedDomain) {
        // Domain is not supported
   }
}

Error Codes

Error Code Description
BlockchainIsDown Thrown when you resolve a domain and its naming service blockchain network is down.
InconsistentDomainArray Thrown when you attempt to retrieve the locations of multiple domains with different naming services. The location of a domain contains the blockchain, networkId, and valuable metadata like owner, resolver, registry addresses, and provider URL of that domain.
IncorrectAddress Thrown when you attempt to retrieve the reverse record of an incorrect wallet address.
IncorrectContractAddress Thrown when using an incorrect contract address with the current resolution instance.
InvalidDomain Thrown when you resolve an invalid domain address.
NotImplemented Thrown when you use a method of the current resolution instance not supported by the naming service you're resolving from. For example, using the getDns(), batchOwners(), getDomainName(), getLocations(), and getTokenUri() methods for the Zilliqa Name Service (ZNS).
RecordNotFound Thrown when you resolve an undefined record of a domain. For example, resolving the Twitter handle of a domain that doesn't have one.
ReverseResolutionNotSpecified Thrown when reverse resolution is not configured for an address.
UnknownCurrency Thrown when you resolve a domain with a currency not supported by the current resolution instance.
UnknownError Thrown when an unknown error occurs while resolving a domain with the current resolution instance.
UnregisteredDomain Thrown when you resolve a domain not owned by any address.
UnspecifiedResolver Thrown when the domain resolver contract address is not found. For example, the domain doesn't have a specified resolver.
UnsupportedCurrency Thrown when you resolve a domain with a currency not supported by the current resolution instance.
UnsupportedDomain Thrown when you resolve a domain with an ending not supported by the current resolution instance.

Use Case: Retrieve a Domain Record

Retrieve any record of a domain. Applications sometimes set custom records for a domain to use within their application. The code snippet below show how to do this in Java.

Copy
Copied
// record consists the value of the requested record
// use this value in your application
String record = resolution.getRecord("ryan.crypto", "custom.record.value");
assertEquals("Example custom record value", record);

Use Case: Resolve Addresses Existing on Multiple Blockchains

The resolution library provides a method for resolving the addresses of tickers for different blockchains (e.g. USDT exists on EOS, ERC20, OMNI, and TRON blockchains). The code snippet below show how to do this in Java.

Copy
Copied
// receiverUSDTAddress consists address for receiving USDT on Ethereum (ERC20 version)
// use this address as recipient of the payment
String receiverUSDTAddress = resolution.getMultiChainAddress("udtestdev-usdt.crypto", "USDT", "ERC20");