Categorygithub.com/wealdtech/go-ens/v3
modulepackage
3.6.0
Repository: https://github.com/wealdtech/go-ens.git
Documentation: pkg.go.dev

# README

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/v3

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 Ethereum 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:

client, err := ethclient.Dial("https://infura.io/v3/SECRET")
name, err := ens.NewName(client, "mydomain.eth")

Addresses can be set and obtained using the address functions, for example to get an address:

COIN_TYPE_ETHEREUM := uint64(60)
address, err := name.Address(COIN_TYPE_ETHEREUM)

ENS supports addresses for multiple coin types; values of coin types can be found at https://github.com/satoshilabs/slips/blob/master/slip-0044.md

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 (
	"fmt"

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

func main() {
	// Replace SECRET with your own access token for this example to work.
	client, err := ethclient.Dial("https://mainnet.infura.io/v3/SECRET")
	if err != nil {
		panic(err)
	}

	// Resolve a name to an address.
	domain := "ethereum.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

# Packages

No description provided by the author
No description provided by the author

# Functions

ContenthashToString turns EIP-1577 binary format in to EIP-1577 text format.
CreateRegistrySession creates a session suitable for multiple calls.
DeriveTokenID derive tokenID from the ENS domain.
DNSWireFormat turns a domain name in to wire format.
DNSWireFormatDomainHash hashes a domain name in wire format.
Domain obtains the domain of an ENS name, including subdomains.
DomainLevel calculates the level of the domain presented.
DomainPart obtains a part of a name Positive parts start at the lowest-level of the domain and work towards the top-level domain.
Format provides a string version of an address, reverse resolving it if possible.
LabelHash generates a simple hash for a piece of a name.
NameHash generates a hash from a name that can be used to look up the name in ENS.
NewAuctionRegistrar creates a new auction registrar for a given domain.
NewAuctionRegistrarAt creates an auction registrar for a given domain at a given address.
NewBaseRegistrar obtains the registrar contract for a given domain.
NewDeed obtains the deed contract for a given domain.
NewDeedAt creates a deed contract at a given address.
NewDNSRegistrar obtains the registrar contract for a given domain.
NewDNSResolver creates a new DNS resolver for a given domain.
NewDNSResolverAt creates a new DNS resolver for a given domain at a given address.
NewDNSSECOracle obtains the DNSSEC oracle contract for a given domain.
NewETHController creates a new controller for a given domain.
NewETHControllerAt creates a .eth controller at a given address.
NewName creates an ENS name structure.
NewRegistry obtains the ENS registry.
NewRegistryAt obtains the ENS registry at a given address.
NewResolver obtains an ENS resolver for a given domain.
NewResolverAt obtains an ENS resolver at a given address.
NewReverseRegistrar obtains the reverse registrar.
NewReverseRegistrarAt obtains the reverse registrar at a given address.
NewReverseResolver obtains the reverse resolver.
NewReverseResolverAt obtains the reverse resolver at a given address.
NewReverseResolverFor creates a reverse resolver contract for the given address.
NormaliseDomain turns ENS domain in to normal form.
NormaliseDomainStrict turns ENS domain in to normal form, using strict DNS rules (e.g.
Normalize normalizes a name according to the ENS rules.
PublicResolverAddress obtains the address of the public resolver for a chain.
RegistrarContractAddress obtains the registrar contract address for a given domain.
RegistryContractAddress obtains the address of the registry contract for a chain.
RegistryContractFromRegistrar obtains the registry contract given an existing registrar contract.
Resolve resolves an ENS name in to an Etheruem address.
ReverseResolve resolves an address in to an ENS name.
SetResolver sets the resolver for a name.
SetSubdomainOwner sets the owner for a subdomain of a name.
StringToContenthash turns EIP-1577 text format in to EIP-1577 binary format.
Tld obtains the top-level domain of an ENS name.
UnqualifiedName strips the root from the domain and ensures the result is suitable as a name.

# Variables

UnknownAddress is the address to which unknown entries resolve.

# Structs

AuctionEntry is an auction entry.
AuctionRegistrar is the structure for the auction registrar contract.
BaseRegistrar is the structure for the registrar.
Deed is the structure for the deed.
DNSRegistrar is the structure for the registrar.
DNSResolver is the structure for the DNS resolver contract.
DNSSECOracle is the structure for the DNSSEC oracle.
ETHController is the structure for the .eth controller contract.
Name represents an ENS name, for example 'foo.bar.eth'.
Registry is the structure for the registry contract.
Resolver is the structure for the resolver contract.
ReverseRegistrar is the structure for the reverse registrar.
ReverseResolver is the structure for the reverse resolver contract.