Resolution is a library for interacting with blockchain domain names. It can be used to retrieve payment addresses and IPFS hashes for decentralized websites.
Resolution is primarily built and maintained by Unstoppable Domains.
pod 'UnstoppableDomainsResolution', '~> 5.1.0'
package.dependencies.append(
.package(url: "https://github.com/unstoppabledomains/resolution-swift", from: "5.0.0")
)
pod update UnstoppableDomainsResolution
package.dependencies.append(
.package(url: "https://github.com/unstoppabledomains/resolution-swift", from: "<latest version number>")
)
NOTE: make sure an instance of the Resolution class is not deallocated until the asyncronous call brings in the result. Your code is the only owner of the instance so keep it as long as you need it.
import UnstoppableDomainsResolution
guard let resolution = try? Resolution() else {
print ("Init of Resolution instance with default parameters failed...")
return
}
Version 0.3.0 introduced the Configurations
struct that is used for configuring each connected naming service.
Library supports three networks at the moment Ethereum, Polygon and Zilliqa. You can update each network separately.
let resolution = try Resolution(configs: Configurations(
uns: UnsLocations = UnsLocations(
layer1: NamingServiceConfig(
providerUrl: "https://eth-mainnet.alchemyapi.io/v2/_BDuTLPgioYxULIE5cGq3wivWAJborcM",
network: "mainnet"),
layer2: NamingServiceConfig(
providerUrl: "https://polygon-mainnet.g.alchemy.com/v2/bKmEKAC4HJUEDNlnoYITvXYuhrIshFsa",
network: "polygon-mainnet"),
zlayer: NamingServiceConfig(
providerUrl: "https://api.zilliqa.com",
network: "mainnet")
)
);
resolution.addr(domain: "brad.crypto", ticker: "eth") { (result) in
switch result {
case .success(let returnValue):
ethAddress = returnValue
domainReceived.fulfill()
case .failure(let error):
XCTFail("Expected Eth Address, but got \(error)")
}
}
Version 0.1.3 introduced the batchOwners(domains: _, completion: _ )
method which adds additional convenience when making multiple domain owner queries.
This method is only compatible with uns-based domains. Using this method with any other domain type will throw the error:
ResolutionError.methodNotSupported
.
As opposed to the single owner(domain: _, completion: _)
method, this batch request will return an array of owners [String?]
. If the the domain is not registered or its value is null
, the corresponding array element of the response will be nil
without throwing an error.
resolution.batchOwners(domains: ["brad.crypto", "homecakes.crypto"]) { result in
switch result {
case .success(let returnValue):
// returnValue: [String: String?] = <map of domains to owner address>
let domainOwner = returnValue
case .failure(let error):
XCTFail("Expected owner, but got \(error)")
}
}
resolution.locations(domains: ["brad.crypto", "homecakes.crypto"]) { result in
switch result {
case .success(let returnValue):
// returnValue: [String: String?] = <map of domains to domain locations>
let locations = returnValue
case .failure(let error):
XCTFail("Expected owner, but got \(error)")
}
}
Make sure your app has AppTransportSecurity settings to allow HTTP access to the
https://main-rpc.linkpool.io
domain.
By default, this library uses the native iOS networking API to connect to the internet. If you want the library to use your own networking layer instead, you must conform your networking layer to the NetworkingLayer
protocol. This protocol requires only one method to be implemented: makeHttpPostRequest(url:, httpMethod:, httpHeaderContentType:, httpBody:, completion:)
. Using this method will bypass the default behavior and delegate the request to your own networking code.
For example, construct the Resolution instance like so:
guard let resolution = try? Resolution(networking: MyNetworkingApi) else {
print ("Init of Resolution instance failed...")
return
}
If the domain you are attempting to resolve is not registered or doesn't contain the information you are requesting, this framework will return a ResolutionError
with the possible causes below. We advise creating customized errors in your app based on the return value of the error.
enum ResolutionError: Error {
case unregisteredDomain
case unsupportedDomain
case recordNotFound
case recordNotSupported
case unsupportedNetwork
case unspecifiedResolver
case unknownError
case proxyReaderNonInitialized
case registryAddressIsNotProvided
case inconsistentDomainArray
case methodNotSupported
case tooManyResponses
case executionReverted
case badRequestOrResponse
case unsupportedServiceName
case invalidDomainName
case contractNotInitialized
case reverseResolutionNotSpecified
}
Please see the Resolution-Swift Error Codes page for details of the specific error codes.
Contributions to this library are more than welcome. The easiest way to contribute is through GitHub issues and pull requests.
Once your app has a working Unstoppable Domains integration, register it here. Registered apps appear on the Unstoppable Domains homepage and Applications page — putting your app in front of tens of thousands of potential customers per day.
Also, every week we select a newly-integrated app to feature in the Unstoppable Update newsletter. This newsletter is delivered to straight into the inbox of ~100,000 crypto fanatics — all of whom could be new customers to grow your business.
Join our discord community and ask questions.
We're always looking for ways to improve how developers use and integrate our products into their applications. We'd love to hear about your experience to help us improve by taking our survey.
link |
Stars: 24 |
Last commit: 1 week ago |
.zil
domains from Polygon and Ethereum networksResolution#reverse
and Resolution#reverseTokenId
methodsSwiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics