status-go/vendor/github.com/wealdtech/go-ens/v3
Andrea Maria Piana 9f2a4b378f
Verify ens endpoint, only against mainnet (#1657)
* String payload

* Verify ENS Names

* Update status-protocol-go
2019-11-04 11:08:22 +01:00
..
contracts Verify ens endpoint, only against mainnet (#1657) 2019-11-04 11:08:22 +01:00
util Verify ens endpoint, only against mainnet (#1657) 2019-11-04 11:08:22 +01:00
.gitignore Verify ens endpoint, only against mainnet (#1657) 2019-11-04 11:08:22 +01:00
.travis.yml Verify ens endpoint, only against mainnet (#1657) 2019-11-04 11:08:22 +01:00
LICENSE Verify ens endpoint, only against mainnet (#1657) 2019-11-04 11:08:22 +01:00
README.md Verify ens endpoint, only against mainnet (#1657) 2019-11-04 11:08:22 +01:00
auctionregistrar.go Verify ens endpoint, only against mainnet (#1657) 2019-11-04 11:08:22 +01:00
baseregistrar.go Verify ens endpoint, only against mainnet (#1657) 2019-11-04 11:08:22 +01:00
contenthash.go Verify ens endpoint, only against mainnet (#1657) 2019-11-04 11:08:22 +01:00
deed.go Verify ens endpoint, only against mainnet (#1657) 2019-11-04 11:08:22 +01:00
dnsregistrar.go Verify ens endpoint, only against mainnet (#1657) 2019-11-04 11:08:22 +01:00
dnsresolver.go Verify ens endpoint, only against mainnet (#1657) 2019-11-04 11:08:22 +01:00
dnssecoracle.go Verify ens endpoint, only against mainnet (#1657) 2019-11-04 11:08:22 +01:00
ethcontroller.go Verify ens endpoint, only against mainnet (#1657) 2019-11-04 11:08:22 +01:00
go.mod Verify ens endpoint, only against mainnet (#1657) 2019-11-04 11:08:22 +01:00
go.sum Verify ens endpoint, only against mainnet (#1657) 2019-11-04 11:08:22 +01:00
misc.go Verify ens endpoint, only against mainnet (#1657) 2019-11-04 11:08:22 +01:00
name.go Verify ens endpoint, only against mainnet (#1657) 2019-11-04 11:08:22 +01:00
namehash.go Verify ens endpoint, only against mainnet (#1657) 2019-11-04 11:08:22 +01:00
registrar.go Verify ens endpoint, only against mainnet (#1657) 2019-11-04 11:08:22 +01:00
registry.go Verify ens endpoint, only against mainnet (#1657) 2019-11-04 11:08:22 +01:00
resolver.go Verify ens endpoint, only against mainnet (#1657) 2019-11-04 11:08:22 +01:00
reverseregistrar.go Verify ens endpoint, only against mainnet (#1657) 2019-11-04 11:08:22 +01:00
reverseresolver.go Verify ens endpoint, only against mainnet (#1657) 2019-11-04 11:08:22 +01:00

README.md

go-ens

Tag License GoDoc Travis CI codecov.io Go Report Card

Go module to simplify interacting with the Ethereum Name Service contracts.

Table of Contents

Install

go-ens is a standard Go module which can be installed with:

go get github.com/wealdtech/go-ens

Usage

go-ens provides simple access to the Ethereum Name Service (ENS) contracts.

Resolution

The most commonly-used feature of ENS is resolution: converting an ENS name to an address. go-ens provides a simple call to allow this:

address, err := ens.Resolve(client, domain)

where client is a connection to an Ethereum client and domain is the fully-qualified name you wish to resolve (e.g. foo.mydomain.eth) (full examples for using this are given in the Example section below).

The reverse process, converting an address to an ENS name, is just as simple:

domain, err := ens.ReverseResolve(client, address)

Note that if the address does not have a reverse resolution this will return "". If you just want a string version of an address for on-screen display then you can use ens.Format(), for example:

fmt.Printf("The address is %s\n", ens.Format(client, address))

This will carry out reverse resolution of the address and print the name if present; if not it will print a formatted version of the address.

Management of names

A top-level name is one that sits directly underneath .eth, for example mydomain.eth. Lower-level names, such as foo.mydomain.eth are covered in the following section. go-ens provides a simplified Name interface to manage top-level, removing the requirement to understand registrars, controllers, etc.

Starting out with names in go-ens is easy:

name, err := ens.Name("mydomain.eth")

Registering and extending names

Most operations on a domain will involve setting resolvers and resolver information.

Management of subdomains

Because subdomains have their own registrars they do not work with the Name interface.

Example

package main

import (
    "github.com/ethereum/go-ethereum/ethclient"
	ens "github.com/wealdtech/go-ens"
)

func main() {
    client, err := ethclient.Dial("https://infura.io/v3/SECRET")
    if err != nil {
        panic(err)
    }

    // Resolve a name to an address
    domain := "wealdtech.eth"
    address, err := ens.Resolve(client, domain)
    if err != nil {
        panic(err)
    }
    fmt.Printf("Address of %s is %s\n", domain, address.Hex())

    // Reverse resolve an address to a name
    reverse, err := ens.ReverseResolve(client, address)
    if err != nil {
        panic(err)
    }
    if reverse == "" {
      fmt.Printf("%s has no reverse lookup\n", address.Hex())
    } else {
      fmt.Printf("Name of %s is %s\n", address.Hex(), reverse)
    }
}

Maintainers

Jim McDonald: @mcdee.

Contribute

Contributions welcome. Please check out the issues.

License

Apache-2.0 © 2019 Weald Technology Trading Ltd