Edit this page


This page details basic configuration and usage of the resolution-swift library.


Resolution libraries require a connection to the Ethereum network to resolve .crypto and .eth domains. To initialize the library, you need to specify an Ethereum node service provider. Once the instance is created you can begin resolving domains. Below are examples of how to initialize the library with different providers.

Provider URL

Each of the resolution libraries supports an Ethereum provider url for configuration. You can obtain a provider url from a service like Alchemy where obtaining an API key is free and only requires creating an account.

To choose an alternative Ethereum provider see Nodes as a Service guide.


Unstoppable libraries use Infura as a provider by default without restrictions and rate limits for UNS resolution. Default configuration can be considered production-ready.

import UnstoppableDomainsResolution

let infuraApiKey = INFURA_PROJECT_ID

guard let resolution = try? Resolution(
    configs: Configurations(
        uns: UnsLocations(
            layer1: NamingServiceConfig(
                        providerUrl: "https://mainnet.infura.io/v3/" + infuraApiKey,
                        network: "mainnet"),
            layer2: NamingServiceConfig(
                        providerUrl: "https://polygon-mainnet.infura.io/v3/" + infuraApiKey,
                        network: "polygon-mainnet")
) else {
  print ("Init of Resolution instance with custom parameters failed...")

Make sure to allow mainnet.infura.io and polygon-mainnet.infura.io or simply https://*.infura.io (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.

  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.

import UnstoppableDomainsResolution

guard let resolution = try? Resolution() else {
  print ("Init of Resolution instance with default parameters failed...")

resolution.addr(domain: "domain-with-error.crypto", ticker: "ETH") { result in
    switch result {
        case .success(let returnValue):
            // Success flow
        case .failure(let error):
            switch error {
                case ResolutionError.unregisteredDomain:
                    // Domain is not registered

                case ResolutionError.recordNotFound:
                    // Crypto record is not found (or empty)

                case ResolutionError.unspecifiedResolver:
                    // Domain is not configured (empty resolver)

                case ResolutionError.unsupportedDomain:
                    // Domain is not supported

Error Codes

Error Code Description
contractNotInitialized Thrown when the proxy reader of the current resolution instance has not been initialized.
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.
invalidDomainName Thrown when you resolve an invalid domain address.
methodNotSupported 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 batchOwners(), getTokenUri(), locations(), and getDomainName() methods for the Zilliqa Name Service (ZNS).
proxyReaderNonInitialized Thrown when the registry address of the current resolution instance has not been initialized.
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.
recordNotSupported Thrown when you resolve an unsupported domain record.
registryAddressIsNotProvided Thrown when using an incorrect contract address with the current resolution instance.
unregisteredDomain Thrown when you resolve a domain not owned by any address.
unknownError Thrown when an unknown error occurs while resolving a domain with the current resolution instance.
unspecifiedResolver Thrown when the domain resolver contract address is not found. For example, the domain doesn't have a specified resolver.
unsupportedDomain Thrown when you resolve a domain with an ending not supported by the current resolution instance.
unsupportedServiceName Thrown when using an unsupported naming service with 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 Swift.

// lookup specific records
resolution.record(domain: "ryan.crypto", record: "custom.record.value") { result in
  switch result {
    case .success(let returnValue):
      // Example custom record value
      let recordValue = returnValue
    case .failure(let error):
      print("Expected record value, but got \(error)")

Asking For Help

Please don't be shy; we're here to help. Join our Discord channel for real-time support from UD and the community if you need assistance integrating your app.