resolution

package module
v3.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 19, 2023 License: MIT Imports: 26 Imported by: 0

README

Test Lint Go Report Card GoDoc Unstoppable Domains Documentation Get help on Discord

resolution-go

resolution-go is a library for interacting with blockchain domain names. It can be used to retrieve payment addresses and IPFS hashes for decentralized websites.

resolution-go is primarily built and maintained by Unstoppable Domains.

Resolution supports different decentralized domains. Please, refer to the Top Level Domains List

Installing resolution-go

go get github.com/unstoppabledomains/resolution-go/v3

Updating resolution-go

go get -u github.com/unstoppabledomains/resolution-go/v3

Using Resolution


NOTE

From version 3.2.0, we introduce a new interface to handle multiple naming services domain resolution.

If you wish to migrate to the new interface to be able resolve other naming services such as ENS, please reference the new interface.


Web3Domain Resolution

We are currently support the following naming services. More naming service on other blockchain are coming...

  • UNS: .x, .crypto, .go etc...
  • ZNS: .zil
  • ENS: .eth, .kred, .xyz, .luxe
Initialize with Unstoppable Domains' Proxy Provider
package main

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

func main() {
	// obtain a key from https://unstoppabledomains.com/partner-api-dashboard if you are a partner
	web3domain, _ := resolution.NewWeb3DomainBuilder().SetUdClient("<api_key>").Build()
}

Initialize with Custom Providers Configuration

package main

import (
	"fmt"

	"github.com/Zilliqa/gozilliqa-sdk/provider"
	"github.com/ethereum/go-ethereum/ethclient"
	"github.com/unstoppabledomains/resolution-go/v3"
)

func main() {
	// obtain a key from https://www.infura.io
	ethereumUrl := "https://mainnet.infura.io/v3/<infura_api_key>"
	maticUrl := "https://polygon-mainnet.infura.io/v3/<infura_api_key>"

	web3DomainBuilder := resolution.NewWeb3DomainBuilder()
	ethBackend, _ := ethclient.Dial(ethereumUrl)
	maticBackend, _ := ethclient.Dial(maticUrl)

	web3DomainBuilder.SetEthContractBackend(backend)
	web3DomainBuilder.SetMaticContractBackend(backendL2)

	w3bDomain, _ = web3DomainBuilder.Build()
}
Resolve web3 domains example
package main

import (
	"fmt"

	"github.com/Zilliqa/gozilliqa-sdk/provider"
	"github.com/ethereum/go-ethereum/ethclient"
	"github.com/unstoppabledomains/resolution-go/v3"
	"github.com/unstoppabledomains/resolution-go/v3/namingservice"
)

func main() {
	web3Domain, _ := resolution.NewWeb3DomainBuilder().SetUdClient("<api_key>").Build()

	// .x domain - UNS naming service
	unsDomain := "lisa.x"
	lisaAddress, _ := web3Domain.Owner(unsDomain)
	fmt.Printf("Owner of %s is %s\n", unsDomain, lisaAddress)
	lisaEthAddress, _ := web3Domain.Addr(unsDomain, "ETH")
	fmt.Printf("ETH address of %s is %s\n", unsDomain, lisaEthAddress)

	// .eth domain - ENS naming service
	ensDomain := "vitalik.eth"
	vitalikAddress, _ := web3Domain.Owner(ensDomain)
	fmt.Printf("Owner of %s is %s\n", ensDomain, vitalikAddress)
	vitalikEthAddress, _ := web3Domain.Addr(ensDomain, "ETH")
	fmt.Printf("ETH address of %s is %s\n", ensDomain, vitalikEthAddress)

	// .zil domain - ZNS naming service
	znsDomain := "brad.zil"
	bradAddress, _ := web3Domain.Owner(znsDomain)
	fmt.Printf("Owner of %s is %s\n", znsDomain, bradAddress)
	bradEthAddress, _ := web3Domain.Addr(znsDomain, "ETH")
	fmt.Printf("ETH address of %s is %s\n", znsDomain, bradEthAddress)

	//reverse resolution
	address1 := "0x05391f2407B664fbd1dcA5AEa9eEa89A29B946b4"
	foundDomain, _ := web3Domain.ReverseOf(address1)
	fmt.Printf("foundDomain for address %s is %s\n", address1, foundDomain) // tun.x

	address2 := "0x4309325e607de185bd6b091cc2e3cfc9f4d6e2e1"
	foundEthDomain, _ := web3Domain.ReverseOf(address2)
	fmt.Printf("foundDomain for address %s is %s\n", address2, foundEthDomain) // unimev.eth

	foundDomains, _ := web3Domain.MultiReverseOf(address1) 	// find a list of domains the address revere resolution to
	fmt.Printf("foundDomain for address %s is %v\n", address1, foundDomains) // [tun.x tu-nguyen.eth]


	//get addr records
	coinAddressUnsDomain, _ := web3Domain.Addr(unsDomain, "ETH")
	fmt.Printf("ETH address of %s is %s\n", unsDomain, coinAddressUnsDomain)

	coinAddressEnsDomain, _ := web3Domain.Addr(ensDomain, "ETH")
	fmt.Printf("ETH address of %s is %s\n", ensDomain, coinAddressEnsDomain)

	// For ENS domains, it's crucial to know that a domain is still valid
	ensExpiry, _ := web3Domain.DomainExpiry(ensDomain)
	fmt.Printf("Is %s expired %t\n", ensDomain, ensExpiry.Before(time.Now()))
}

Unstoppable Domain Resolution

Initialize with Unstoppable Domains' Proxy Provider
package main

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

func main() {
	// obtain a key from https://unstoppabledomains.com/partner-api-dashboard if you are a partner
	uns, _ := resolution.NewUnsBuilder().SetUdClient("<api_key>").Build()
}

Initialize with Custom Ethereum Provider Configuration
package main

import (
	"fmt"

	"github.com/Zilliqa/gozilliqa-sdk/provider"
	"github.com/ethereum/go-ethereum/ethclient"
	"github.com/unstoppabledomains/resolution-go/v3"
)

func main() {
	// obtain a key from https://www.infura.io
	var ethereumUrl = "https://mainnet.infura.io/v3/<infura_api_key>"
	var ethereumL2Url = "https://polygon-mainnet.infura.io/v3/<infura_api_key>"

	unsBuilder := resolution.NewUnsBuilder()
	backend, _ := ethclient.Dial(ethereumUrl)
	backendL2, _ := ethclient.Dial(ethereumL2Url)

	unsBuilder.SetContractBackend(backend)
	unsBuilder.SetL2ContractBackend(backendL2)

	uns, _ = unsBuilder.Build()

	zilliqaProvider := provider.NewProvider("https://api.zilliqa.com")
	zns, _ := resolution.NewZnsBuilder().SetProvider(zilliqaProvider).Build()
}
Resolve domains example
package main

import (
	"fmt"

	"github.com/Zilliqa/gozilliqa-sdk/provider"
	"github.com/ethereum/go-ethereum/ethclient"
	"github.com/unstoppabledomains/resolution-go/v3"
	"github.com/unstoppabledomains/resolution-go/v3/namingservice"
)

func main() {
	// Resolve .crypto
	uns, _ := resolution.NewUnsBuilder().SetUdClient("<api_key>").Build()
	ethAddress, _ := uns.Addr("brad.crypto", "ETH")
	fmt.Println("ETH address for brad.crypto is", ethAddress)

	// Resolve.zil
	zns, _ := resolution.NewZnsBuilder().Build()
	btcAddress, _ := zns.Addr("brad.zil", "BTC")
	fmt.Println("BTC address for brad.zil is", btcAddress)

	// Get locations of domains
	uns, _ = resolution.NewUnsBuilder().Build()
	locations, _ := uns.Locations([]string{"ryan.crypto", "brad.crypto"})
	fmt.Println("Locations for ryan.crypto and brad.crypto are", locations)

	// Detect domain naming service
	namingServices := map[string]resolution.NamingService{namingservice.UNS: uns, namingservice.ZNS: zns}
	domainToDetect := "ryan.crypto"
	namingServiceName, _ := resolution.DetectNamingService(domainToDetect)
	if namingServices[namingServiceName] != nil {
		resolvedAddress, _ := namingServices[namingServiceName].Addr(domainToDetect, "ETH")
		fmt.Println("ETH address for", domainToDetect, "is", resolvedAddress)
	}
}
Resolve Wallet Address Examples

NOTE

These example are only applied to UNS using NewUnsBuilder function


Using Addr

This API is used to retrieve wallet address for single address record. (See Cryptocurrency payment section for the record format)

func main() {
	//...
	// homecakes.crypto has `crypto.ETH.address` set to 0xe7474D07fD2FA286e7e0aa23cd107F8379085037
	domain := "homecakes.crypto"
	walletAddress, err := uns.Addr(domain, "ETH")

	if err != nil {
		fmt.Println(err)
	}

	fmt.Printf("Addr for %s ticker %s: %s\n", domain, "ETH", walletAddress)
	// Addr for homecakes.crypto ticker ETH: 0xe7474D07fD2FA286e7e0aa23cd107F8379085037
}
Using GetAddr

This (beta) API can be used to resolve different formats

Resolve single address format (similar to Addr API)

With homecakes.crypto has a crypto.ETH.address record set on-chain:

func main() {
	domain := "homecakes.crypto"
	walletAddress, err := uns.GetAddr(domain, "ETH", "ETH")

	if err != nil {
		fmt.Println(err)
	}

	fmt.Printf("Addr for %s on network %s with token %s: %s\n", domain, "ETH", "ETH", walletAddress)
	// Addr for homecakes.crypto on network ETH with token ETH: 0xe7474D07fD2FA286e7e0aa23cd107F8379085037
}

Resolve multi-chain currency address format (See multi-chain currency)

With aaron.x has a crypto.AAVE.version.ERC20.address record set to 0xCD0DAdAb45bAF9a06ce1279D1342EcC3F44845af. The ERC20 indicates it's a token on ETH network:

func main() {
	domain := "aaron.x"
	walletAddress, err := uns.GetAddr(domain, "ETH", "AAVE")

	if err != nil {
		fmt.Println(err)
	}

	fmt.Printf("Addr for %s on network %s with token %s: %s\n", domain, "ETH", "AAVE", walletAddress)
	// Addr for aaron.x on network ETH with token AAVE: 0xCD0DAdAb45bAF9a06ce1279D1342EcC3F44845af
}

Derive wallet addresses within the same blockchain network and blockchain family.

The API can also be used by crypto exchanges to infer wallet addresses. In centralized exchanges, users have same wallet addresses on different networks with same wallet family. (See Blockchain Family, Network, Token Level Addresses section for the record format)

With blockchain-family-keys.x only has token.EVM.address record on-chain. The API resolves to same wallet address for tokens live on EVM compatible networks.


func main() {
	domain := "blockchain-family-keys.x"
	aaveOnEthWallet, _ := uns.GetAddr(domain, "ETH", "AAVE")
	fmt.Printf("Addr for %s on network %s with token %s: %s\n", domain, "ETH", "AAVE", aaveOnEthWallet)
	// Addr for blockchain-family-keys.x on network ETH with token AAVE: 0xCD0DAdAb45bAF9a06ce1279D1342EcC3F44845af

	ethOnEthWallet, _ := uns.GetAddr(domain, "ETH", "ETH")
	fmt.Printf("Addr for %s on network %s with token %s: %s\n", domain, "ETH", "ETH", ethOnEthWallet)
	// Addr for blockchain-family-keys.x on network ETH with token ETH: 0xCD0DAdAb45bAF9a06ce1279D1342EcC3F44845af

	usdtOnAvax, _ := uns.GetAddr(domain, "AVAX", "USDT")
	fmt.Printf("Addr for %s on network %s with token %s: %s\n", domain, "AVAX", "USDT", usdtOnAvax)
	// Addr for blockchain-family-keys.x on network AVAX with token USDT: 0xCD0DAdAb45bAF9a06ce1279D1342EcC3F44845af
}

With uns-devtest-nickshatilo-withdraw-test2.x only has token.EVM.ETH.address record on chain. The API resolves to the same wallet address for tokens specifically on Ethereum network.

func main() {
	domain := "uns-devtest-nickshatilo-withdraw-test2.x"
	aaveOnEthWallet, _ := uns.GetAddr(domain, "ETH", "AAVE")
	fmt.Printf("Addr for %s on network %s with token %s: %s\n", domain, "ETH", "AAVE", aaveOnEthWallet)
	// Addr for uns-devtest-nickshatilo-withdraw-test2.x on network ETH with token AAVE: 0xCD0DAdAb45bAF9a06ce1279D1342EcC3F44845af

	ethOnEthWallet, _ := uns.GetAddr(domain, "ETH", "ETH")
	fmt.Printf("Addr for %s on network %s with token %s: %s\n", domain, "ETH", "ETH", ethOnEthWallet)
	// Addr for uns-devtest-nickshatilo-withdraw-test2.x on network ETH with token ETH: 0xCD0DAdAb45bAF9a06ce1279D1342EcC3F44845af

	usdtOnAvax, _ := uns.GetAddr(domain, "AVAX", "USDT")
	// won't work
}

The API is compatible with other address formats. If a domain has multiple address formats set, it will follow the algorithm described as follow:

if a domain has following records set:

token.EVM.address
crypto.USDC.version.ERC20.address
token.EVM.ETH.USDC.address
crypto.USDC.address
token.EVM.ETH.address

getAddress(domain, 'ETH', 'USDC') will lookup records in the following order:

1. token.EVM.ETH.USDC.address
2. crypto.USDC.address
3. crypto.USDC.version.ERC20.address
4. token.EVM.ETH.address
5. token.EVM.address

Contributions

Contributions to this library are more than welcome. The easiest way to contribute is through GitHub issues and pull requests.

Use these commands to set up a local development environment (macOS Terminal or Linux shell).

  1. Recommended golang version
  • go1.18
  1. Clone the repository

    git clone https://github.com/unstoppabledomains/resolution-go.git
    cd resolution-go
    
  2. Install dependencies

    go mod download
    
Internal config
Unit tests:

resolution-go library relies on environment variables to load TestNet RPC Urls. This way, our keys don't expose directly to the code. In order to validate the code change, please set these variables to your local environment.

  • L1_TEST_NET_RPC_URL
  • L2_TEST_NET_RPC_URL

Free advertising for integrated apps

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.

Get help

Join our discord community and ask questions.

Help us improve

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.

Documentation

Index

Constants

View Source
const (
	Mainnet string = "mainnet"
	Polygon string = "polygon"
	Mumbai  string = "mumbai"
	Goerli  string = "goerli"
)
View Source
const (
	Layer1 string = "Layer 1"
	Layer2 string = "Layer 2"
)
View Source
const (
	NullAddress = "0x0000000000000000000000000000000000000000"
)

Variables

View Source
var NetworkNameToId = map[string]int{
	Mainnet: 1,
	Polygon: 137,
	Mumbai:  80001,
	Goerli:  5,
}

Functions

func DetectNamingService

func DetectNamingService(domainName string) (string, error)

DetectNamingService helper to detect naming service type for provided domain. Returns ZNS or UNS for valid domain and error if domain is not valid or not supported by resolution-go library.

func ZnsNameHash

func ZnsNameHash(domainName string) (string, error)

ZnsNameHash Namehash for .zil domains

Types

type AddressNotSupportedError added in v3.1.0

type AddressNotSupportedError struct {
	Address string
}

AddressNotSupportedError Error when domain is not supported by the naming service

func (*AddressNotSupportedError) Error added in v3.1.0

func (e *AddressNotSupportedError) Error() string

type DomainNotConfiguredError

type DomainNotConfiguredError struct {
	DomainName string
	Layer      string
}

DomainNotConfiguredError Error when domain does not have a resolver set

func (*DomainNotConfiguredError) Error

func (e *DomainNotConfiguredError) Error() string

type DomainNotRegisteredError

type DomainNotRegisteredError struct {
	DomainName string
	Namehash   string
}

DomainNotRegisteredError Error when domain is missing an owner

func (*DomainNotRegisteredError) Error

func (e *DomainNotRegisteredError) Error() string

type DomainNotSupportedError

type DomainNotSupportedError struct {
	DomainName string
}

DomainNotSupportedError Error when domain is not supported by the naming service

func (*DomainNotSupportedError) Error

func (e *DomainNotSupportedError) Error() string

type Ens added in v3.2.0

type Ens struct {
	// contains filtered or unexported fields
}

Ens is a naming service handles Ethereum naming service resolution.

func (*Ens) Addr added in v3.2.0

func (e *Ens) Addr(domainName, ticker string) (string, error)

func (*Ens) AddrVersion added in v3.2.0

func (e *Ens) AddrVersion(domainName string, ticker string, version string) (string, error)

func (*Ens) AllRecords added in v3.2.0

func (e *Ens) AllRecords(domainName string) (map[string]string, error)

AllRecords Retrieve all records of a domain. Returns result in string or empty string record is not found. Deprecated: This method will be removed in future releases

func (*Ens) CoinAddress added in v3.2.0

func (e *Ens) CoinAddress(domainName string, coin string) (string, error)

func (*Ens) ContentHash added in v3.2.0

func (e *Ens) ContentHash(domainName string) (string, error)

func (*Ens) DNS added in v3.2.0

func (e *Ens) DNS(domainName string, types []dnsrecords.Type) ([]dnsrecords.Record, error)

func (*Ens) DomainExpiry added in v3.2.0

func (e *Ens) DomainExpiry(domainName string) (time.Time, error)

func (*Ens) Email added in v3.2.0

func (e *Ens) Email(domainName string) (string, error)

func (*Ens) HTTPUrl added in v3.2.0

func (e *Ens) HTTPUrl(domainName string) (string, error)

HTTPUrl Retrieve the http redirect url of a domain.

func (*Ens) IpfsHash added in v3.2.0

func (e *Ens) IpfsHash(domainName string) (string, error)

IpfsHash Retrieve hash of IPFS website attached to domain.

func (*Ens) IsSupportedDomain added in v3.2.0

func (e *Ens) IsSupportedDomain(domainName string) (bool, error)

func (*Ens) Locations added in v3.2.0

func (e *Ens) Locations(domainNames []string) (map[string]namingservice.Location, error)

Locations Retrieve locations of domains Returns key-value map of domain names to location

func (*Ens) Namehash added in v3.2.0

func (e *Ens) Namehash(domainName string) (string, error)

func (*Ens) Owner added in v3.2.0

func (e *Ens) Owner(domainName string) (string, error)

func (*Ens) Record added in v3.2.0

func (e *Ens) Record(domainName string, key string) (string, error)

func (*Ens) Records added in v3.2.0

func (e *Ens) Records(domainName string, keys []string) (map[string]string, error)

func (*Ens) Resolver added in v3.2.0

func (e *Ens) Resolver(domainName string) (string, error)

func (*Ens) ReverseOf added in v3.2.0

func (e *Ens) ReverseOf(addr string) (string, error)

func (*Ens) TextRecord added in v3.2.0

func (e *Ens) TextRecord(domainName, key string) (string, error)

func (*Ens) TokenURI added in v3.2.0

func (e *Ens) TokenURI(domainName string) (string, error)

TokenURI returns ERC721 metadata token URI

func (*Ens) TokenURIMetadata added in v3.2.0

func (e *Ens) TokenURIMetadata(domainName string) (TokenMetadata, error)

TokenURIMetadata returns ERC721 metadata

func (*Ens) Unhash added in v3.2.0

func (e *Ens) Unhash(domainHash string) (string, error)

type EnsBuilder added in v3.2.0

type EnsBuilder interface {
	// SetContractBackend set Ethereum backend for communication with Ens registry
	SetContractBackend(backend bind.ContractBackend) EnsBuilder

	// SetContractBackendProviderUrl set Ethereum backend Rpc URL
	SetContractBackendProviderUrl(url string) EnsBuilder

	// SetMetadataClient set http backend for communication with ERC721 metadata server
	SetMetadataClient(backend MetadataClient) EnsBuilder

	// Set SetEthereumNetwork
	SetEthereumNetwork(network string) EnsBuilder

	// Build Uns instance
	Build() (*Ens, error)
}

func NewEnsBuilder added in v3.2.0

func NewEnsBuilder() EnsBuilder

type EnsConfigurationError added in v3.2.0

type EnsConfigurationError struct {
	InvalidField string
}

func (*EnsConfigurationError) Error added in v3.2.0

func (e *EnsConfigurationError) Error() string

type EnsInvalidCoinType added in v3.2.0

type EnsInvalidCoinType struct {
	CoinType string
}

func (*EnsInvalidCoinType) Error added in v3.2.0

func (e *EnsInvalidCoinType) Error() string

type EnsService added in v3.2.0

type EnsService struct {
	// contains filtered or unexported fields
}

Ens is a naming service

type InvalidDomainNameReturnedError

type InvalidDomainNameReturnedError struct {
	Namehash   string
	DomainName string
}

InvalidDomainNameReturnedError Error when ERC721 metadata provides returns incorrect domain name

func (*InvalidDomainNameReturnedError) Error

type MetadataClient

type MetadataClient interface {
	Get(url string) (resp *http.Response, err error)
}

type MethodIsNotSupportedError

type MethodIsNotSupportedError struct {
	NamingServiceName string
}

MethodIsNotSupportedError Error when naming services does not support called method

func (*MethodIsNotSupportedError) Error

func (e *MethodIsNotSupportedError) Error() string

type NamingService

type NamingService interface {
	// Records Retrieve records of domain.
	// Keys must be provided in raw format according to specification.
	// Keys specification: https://docs.unstoppabledomains.com/domain-registry-essentials/records-reference.
	// Supported keys reference: https://github.com/unstoppabledomains/dot-crypto/blob/master/src/supported-keys/supported-keys.json.
	// It returns key-value map of specified keys set on provided domain. Map can contain empty strings if keys are not found.
	Records(domainName string, keys []string) (map[string]string, error)

	// Record Retrieve single record of domain.
	// Keys must be provided in raw format according to specification.
	// Keys specification: https://docs.unstoppabledomains.com/domain-registry-essentials/records-reference.
	// Supported keys reference: https://github.com/unstoppabledomains/dot-crypto/blob/master/src/supported-keys/supported-keys.json.
	// Returns result in string or empty string if no result found.
	Record(domainName string, key string) (string, error)

	// Addr Retrieve the value of domain's currency ticker.
	// Ticker must contain cryptocurrency like: BTC, ETH.
	// Returns result in string or empty string if no result found.
	Addr(domainName string, ticker string) (string, error)

	// AddrVersion Retrieve the version value of domain's currency ticker.
	// This method should be used to query multi-chain currency like USDT.
	// Returns result in string or empty string if no result found.
	AddrVersion(domainName string, ticker string, version string) (string, error)

	// Email Retrieve the email of domain.
	// Returns result in string or empty string if no result found.
	Email(domainName string) (string, error)

	// Resolver Retrieve the resolver address.
	// Returns result or DomainNotConfiguredError if resolver is not found.
	Resolver(domainName string) (string, error)

	// Owner Retrieve the owner address.
	// Returns result or DomainNotRegisteredError if owner is not found.
	Owner(domainName string) (string, error)

	// IpfsHash Retrieve hash of IPFS website attached to domain.
	IpfsHash(domainName string) (string, error)

	// HTTPUrl Retrieve the http redirect url of a domain.
	HTTPUrl(domainName string) (string, error)

	// AllRecords Retrieve all records of a domain.
	// Returns result in string or empty string record is not found.
	// Deprecated: This method will be removed in future releases
	AllRecords(domainName string) (map[string]string, error)

	// Locations Retrieve locations of domains
	// Returns key-value map of domain names to location
	Locations(domainNames []string) (map[string]namingservice.Location, error)

	// DNS Retrieve the DNS records of a domain.
	// Returns a set of valid and filtered non-empty DNS records attached to domain.
	DNS(domainName string, types []dnsrecords.Type) ([]dnsrecords.Record, error)

	// IsSupportedDomain checks whether domain name is supported by the naming service.
	IsSupportedDomain(domainName string) (bool, error)

	// DomainExpiry checks whether domain name is expired.
	DomainExpiry(domainName string) (time.Time, error)

	// TokenURI returns ERC721 metadata token URI
	TokenURI(domainName string) (string, error)

	// TokenURIMetadata returns ERC721 metadata
	TokenURIMetadata(domainName string) (TokenMetadata, error)

	// Unhash returns a domain name from a hash using TokenMetadata.Name field and ensures it indeed matches the given hash.
	// domainHash should be in hex numeric string format, for example: "0x29bf1b111e709f0953848df35e419490fbad5d316690e4de61adc52695ddf9f3"
	// ERC721 Token ID could be passed to this method but should be converted to hex numeric string before usage.
	//
	// Examples of usage:
	//
	// domainName, err := NamingService.Unhash("0x29bf1b111e709f0953848df35e419490fbad5d316690e4de61adc52695ddf9f3")
	// domainName, err := NamingService.Unhash("0x691f36df38168d9297e784f45a87257a70c58c4040d469c6d0b91d253a837e32")
	//
	// Usage with ERC721 token id:
	//
	// var erc721TokenID big.Int
	// erc721TokenID.SetString("47548000072528700265403562077742902343248290986511625310517899838602191535666", 10)
	// domainHash := hex.EncodeToString(erc721TokenID.Bytes())
	// domainName, err := NamingService.Unhash(domainHash)
	//
	Unhash(domainHash string) (string, error)

	// Namehash returns a namehash of a domain following the EIP-137 standard
	Namehash(domainName string) (string, error)

	ReverseOf(addr string) (string, error)
}

NamingService Unstoppable supports multiple naming services (.zil and .crypto). Each naming service implements shared interface and returns similar record types.

type NetworkContracts

type NetworkContracts map[string]contracts

type TokenMetadata

type TokenMetadata struct {
	Name            string                   `json:"name"`
	Description     string                   `json:"description"`
	Image           string                   `json:"image"`
	ExternalUrl     string                   `json:"-"`
	ExternalLink    string                   `json:"external_link"`
	ImageData       string                   `json:"image_data"`
	BackgroundColor string                   `json:"background_color"`
	AnimationUrl    string                   `json:"animation_url"`
	YoutubeUrl      string                   `json:"youtube_url"`
	Properties      TokenMetadataProperties  `json:"properties"`
	Attributes      []TokenMetadataAttribute `json:"attributes"`
}

func (*TokenMetadata) UnmarshalJSON added in v3.2.0

func (tm *TokenMetadata) UnmarshalJSON(data []byte) error

type TokenMetadataAttribute

type TokenMetadataAttribute struct {
	DisplayType string      `json:"display_type"`
	TraitType   string      `json:"trait_type"`
	Value       interface{} `json:"value"`
}

type TokenMetadataProperties

type TokenMetadataProperties struct {
	Records map[string]string `json:"records"`
}

type Uns

type Uns struct {
	// contains filtered or unexported fields
}

Uns is a naming service handles Unstoppable domains resolution.

func (*Uns) Addr

func (c *Uns) Addr(domainName string, ticker string) (string, error)

func (*Uns) AddrVersion

func (c *Uns) AddrVersion(domainName string, ticker string, version string) (string, error)

func (*Uns) AllRecords

func (c *Uns) AllRecords(domainName string) (map[string]string, error)

func (*Uns) DNS

func (c *Uns) DNS(domainName string, types []dnsrecords.Type) ([]dnsrecords.Record, error)

func (*Uns) Data

func (c *Uns) Data(domainName string, keys []string) (*struct {
	Resolver common.Address
	Owner    common.Address
	Values   []string
}, error)

Data Get raw data attached to domain

func (*Uns) DomainExpiry added in v3.2.0

func (c *Uns) DomainExpiry(domainName string) (time.Time, error)

func (*Uns) Email

func (c *Uns) Email(domainName string) (string, error)

func (*Uns) GetAddr added in v3.1.0

func (c *Uns) GetAddr(domainName, family, token string) (string, error)

func (*Uns) HTTPUrl

func (c *Uns) HTTPUrl(domainName string) (string, error)

func (*Uns) IpfsHash

func (c *Uns) IpfsHash(domainName string) (string, error)

func (*Uns) IsSupportedDomain

func (c *Uns) IsSupportedDomain(domainName string) (bool, error)

func (*Uns) Locations

func (c *Uns) Locations(domainNames []string) (map[string]namingservice.Location, error)

func (*Uns) Namehash

func (c *Uns) Namehash(domainName string) (string, error)

func (*Uns) Owner

func (c *Uns) Owner(domainName string) (string, error)

func (*Uns) Record

func (c *Uns) Record(domainName string, key string) (string, error)

func (*Uns) Records

func (c *Uns) Records(domainName string, keys []string) (map[string]string, error)

func (*Uns) Resolver

func (c *Uns) Resolver(domainName string) (string, error)

func (*Uns) ReverseOf added in v3.1.0

func (c *Uns) ReverseOf(addr string) (string, error)

func (*Uns) TokenURI

func (c *Uns) TokenURI(domainName string) (string, error)

func (*Uns) TokenURIMetadata

func (c *Uns) TokenURIMetadata(domainName string) (TokenMetadata, error)

func (*Uns) Unhash

func (c *Uns) Unhash(domainHash string) (string, error)

type UnsBuilder

type UnsBuilder interface {
	// SetContractBackend set Ethereum backend for communication with UNS registry
	SetContractBackend(backend bind.ContractBackend) UnsBuilder

	// SetContractBackendProviderUrl set Ethereum backend Rpc URL
	SetContractBackendProviderUrl(url string) UnsBuilder

	// SetL2ContractBackend set Ethereum backend for communication with UNS L2registry
	SetL2ContractBackend(backend bind.ContractBackend) UnsBuilder

	// SetL2ContractBackendProviderUrl set Polygon backend Rpc URL
	SetL2ContractBackendProviderUrl(url string) UnsBuilder

	// SetMetadataClient set http backend for communication with ERC721 metadata server
	SetMetadataClient(backend MetadataClient) UnsBuilder

	// SetUdClient set http proxy backends for communication with UNS registry
	SetUdClient(apiKey string) UnsBuilder

	// SetEthereumNetwork set Ethereum network for communication with UNS registry
	SetEthereumNetwork(network string) UnsBuilder

	// SetL2EthereumNetwork set Ethereum network for communication with UNS L2 registry
	SetL2EthereumNetwork(network string) UnsBuilder

	// Build Uns instance
	Build() (*Uns, error)
}

UnsBuilder is a builder to setup and build instance of Uns

func NewUnsBuilder

func NewUnsBuilder() UnsBuilder

NewUnsBuilder Creates builder to setup new instance of Uns

type UnsConfigurationError

type UnsConfigurationError struct {
	Layer        string
	InvalidField string
}

UnsConfigurationError Error when UNS resolution service is configured incorrectly

func (*UnsConfigurationError) Error

func (e *UnsConfigurationError) Error() string

type UnsService

type UnsService struct {
	Layer string
	// contains filtered or unexported fields
}

Uns is a naming service handles Unstoppable domains resolution.

func (*UnsService) DNS

func (c *UnsService) DNS(domainName string, types []dnsrecords.Type) ([]dnsrecords.Record, error)

type Web3Domain added in v3.2.0

type Web3Domain struct {
	// contains filtered or unexported fields
}

func (Web3Domain) Addr added in v3.2.0

func (w3d Web3Domain) Addr(domain, token string) (string, error)

func (Web3Domain) DNS added in v3.2.0

func (w3d Web3Domain) DNS(domain string, types []dnsrecords.Type) ([]dnsrecords.Record, error)

func (Web3Domain) DomainExpiry added in v3.2.0

func (w3d Web3Domain) DomainExpiry(domainName string) (time.Time, error)

func (Web3Domain) Email added in v3.2.0

func (w3d Web3Domain) Email(domain string) (string, error)

func (Web3Domain) HTTPUrl added in v3.2.0

func (w3d Web3Domain) HTTPUrl(domain string) (string, error)

func (Web3Domain) IpfsHash added in v3.2.0

func (w3d Web3Domain) IpfsHash(domain string) (string, error)

func (Web3Domain) Locations added in v3.2.0

func (w3d Web3Domain) Locations(domains []string) (map[string]namingservice.Location, error)

maybe useless

func (Web3Domain) MultiReverseOf added in v3.2.0

func (w3d Web3Domain) MultiReverseOf(addr string) ([]string, error)

func (Web3Domain) Namehash added in v3.2.0

func (w3d Web3Domain) Namehash(domain string) (string, error)

func (Web3Domain) Owner added in v3.2.0

func (w3d Web3Domain) Owner(domain string) (string, error)

func (Web3Domain) Record added in v3.2.0

func (w3d Web3Domain) Record(domain, key string) (string, error)

func (Web3Domain) Resolver added in v3.2.0

func (w3d Web3Domain) Resolver(domain string) (string, error)

func (Web3Domain) ReverseOf added in v3.2.0

func (w3d Web3Domain) ReverseOf(addr string) (string, error)

func (Web3Domain) TokenURI added in v3.2.0

func (w3d Web3Domain) TokenURI(domain string) (string, error)

func (Web3Domain) TokenURIMetadata added in v3.2.0

func (w3d Web3Domain) TokenURIMetadata(domain string) (TokenMetadata, error)

func (Web3Domain) Unhash added in v3.2.0

func (w3d Web3Domain) Unhash(domainHash string) (string, error)

type Web3DomainBuilder added in v3.2.0

type Web3DomainBuilder interface {
	// SetContractBackend set Ethereum backend for communication with Web3Domain registry
	SetEthContractBackend(backend bind.ContractBackend) Web3DomainBuilder

	// SetContractBackendProviderUrl set Ethereum backend Rpc URL
	SetEthContractBackendProviderUrl(url string) Web3DomainBuilder

	// SetL2ContractBackend set Ethereum backend for communication with Web3Domain L2registry
	SetMaticContractBackend(backend bind.ContractBackend) Web3DomainBuilder

	// SetL2ContractBackendProviderUrl set Polygon backend Rpc URL
	SetMaticContractBackendProviderUrl(url string) Web3DomainBuilder

	// SetMetadataClient set http backend for communication with ERC721 metadata server
	SetMetadataClient(backend MetadataClient) Web3DomainBuilder

	// SetUdClient set http proxy backends for communication with Web3Domain registry
	SetUdClient(apiKey string) Web3DomainBuilder

	// SetEthereumNetwork set Ethereum network for communication with Web3Domain registry
	SetEthereumNetwork(network string) Web3DomainBuilder

	// SetL2EthereumNetwork set Ethereum network for communication with Web3Domain L2 registry
	SetMaticNetwork(network string) Web3DomainBuilder

	Build() (*Web3Domain, error)
}

Web3Builder is a builder to setup and build instance of Web3Domain Resolution

func NewWeb3DomainBuilder added in v3.2.0

func NewWeb3DomainBuilder() Web3DomainBuilder

Web3DomainBuilder Creates builder to setup new instance of Web3Domain

type Web3DomainConfigurationError added in v3.2.0

type Web3DomainConfigurationError struct {
	InvalidField string
}

type Zns

type Zns struct {
	// contains filtered or unexported fields
}

Zns is a naming service handles .zil domains resolution.

func (*Zns) Addr

func (z *Zns) Addr(domainName string, ticker string) (string, error)

func (*Zns) AddrVersion

func (z *Zns) AddrVersion(domainName string, ticker string, version string) (string, error)

func (*Zns) AllRecords

func (z *Zns) AllRecords(domainName string) (map[string]string, error)

func (*Zns) DNS

func (z *Zns) DNS(domainName string, types []dnsrecords.Type) ([]dnsrecords.Record, error)

func (*Zns) DomainExpiry added in v3.2.0

func (z *Zns) DomainExpiry(domainName string) (time.Time, error)

func (*Zns) Email

func (z *Zns) Email(domainName string) (string, error)

func (*Zns) HTTPUrl

func (z *Zns) HTTPUrl(domainName string) (string, error)

func (*Zns) IpfsHash

func (z *Zns) IpfsHash(domainName string) (string, error)

func (*Zns) IsSupportedDomain

func (z *Zns) IsSupportedDomain(domainName string) (bool, error)

func (*Zns) Locations

func (z *Zns) Locations(domainNames []string) (map[string]namingservice.Location, error)

func (*Zns) Namehash

func (z *Zns) Namehash(domainName string) (string, error)

func (*Zns) Owner

func (z *Zns) Owner(domainName string) (string, error)

func (*Zns) Record

func (z *Zns) Record(domainName string, key string) (string, error)

func (*Zns) Records

func (z *Zns) Records(domainName string, keys []string) (map[string]string, error)

func (*Zns) Resolver

func (z *Zns) Resolver(domainName string) (string, error)

func (*Zns) ReverseOf added in v3.2.0

func (z *Zns) ReverseOf(_ string) (string, error)

func (*Zns) State

func (z *Zns) State(domainName string) (*ZnsDomainState, error)

State Get raw data attached to domain.

func (*Zns) TokenURI

func (z *Zns) TokenURI(_ string) (string, error)

func (*Zns) TokenURIMetadata

func (z *Zns) TokenURIMetadata(_ string) (TokenMetadata, error)

func (*Zns) Unhash

func (z *Zns) Unhash(_ string) (string, error)

type ZnsBuilder

type ZnsBuilder interface {
	// SetProvider set Zilliqa blockchain provider to communicate with ZNS registry
	SetProvider(provider ZnsProvider) ZnsBuilder
	// SetProvider set Zilliqa network to communicate with ZNS registry
	SetNetwork(network string) ZnsBuilder
	// Build Zns instance
	Build() (*Zns, error)
}

ZnsBuilder is a builder to setup and build instance of Zns service.

func NewZnsBuilder

func NewZnsBuilder() ZnsBuilder

NewZnsBuilder Creates ZNS builder instance.

type ZnsDomainState

type ZnsDomainState struct {
	Resolver string
	Owner    string
	Records  map[string]string
}

ZnsDomainState State of ZNS domain

type ZnsProvider

type ZnsProvider interface {
	GetSmartContractSubState(contractAddress string, params ...interface{}) (string, error)
}

ZnsProvider ZnsProvider

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL