ens

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2019 License: Apache-2.0 Imports: 28 Imported by: 7

README

go-ens

Tag License GoDoc Travis CI codecov.io

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 contracts.

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var UnknownAddress = common.HexToAddress("00")

UnknownAddress is the address to which unknown entries resolve

Functions

func Abi

func Abi(resolver *resolver.ResolverContract, name string) (abi string, err error)

Abi returns the ABI associated with a name

func AuctionRegistrarContract

func AuctionRegistrarContract(client *ethclient.Client, domain string) (registrar *auctionregistrar.AuctionRegistrarContract, err error)

AuctionRegistrarContract obtains the registrar contract for a given domain

func AuctionRegistrarContractAddress

func AuctionRegistrarContractAddress(client *ethclient.Client, domain string) (address common.Address, err error)

AuctionRegistrarContractAddress obtains the registrar contract address for a given domain

func CreateDNSResolverSession

func CreateDNSResolverSession(chainID *big.Int, wallet *accounts.Wallet, account *accounts.Account, passphrase string, contract *dnsresolver.DNSResolverContract, gasPrice *big.Int) *dnsresolver.DNSResolverContractSession

CreateDNSResolverSession creates a session suitable for multiple calls

func CreateRegistrarSession

func CreateRegistrarSession(chainID *big.Int, wallet *accounts.Wallet, account *accounts.Account, passphrase string, contract *auctionregistrar.AuctionRegistrarContract, gasPrice *big.Int) *auctionregistrar.AuctionRegistrarContractSession

CreateRegistrarSession creates a session suitable for multiple calls

func CreateRegistrySession

func CreateRegistrySession(chainID *big.Int, wallet *accounts.Wallet, account *accounts.Account, passphrase string, contract *registry.RegistryContract, gasPrice *big.Int) *registry.RegistryContractSession

CreateRegistrySession creates a session suitable for multiple calls

func CreateResolverSession

func CreateResolverSession(chainID *big.Int, wallet *accounts.Wallet, account *accounts.Account, passphrase string, contract *resolver.ResolverContract, gasPrice *big.Int) *resolver.ResolverContractSession

CreateResolverSession creates a session suitable for multiple calls

func CreateReverseRegistrarSession

func CreateReverseRegistrarSession(chainID *big.Int, wallet *accounts.Wallet, account *accounts.Account, passphrase string, contract *reverseregistrar.ReverseRegistrarContract, gasPrice *big.Int) *reverseregistrar.ReverseRegistrarContractSession

CreateReverseRegistrarSession creates a session suitable for multiple calls

func CreateReverseResolverSession

func CreateReverseResolverSession(chainID *big.Int, wallet *accounts.Wallet, account *accounts.Account, passphrase string, contract *reverseresolver.ReverseResolver, gasPrice *big.Int) *reverseresolver.ReverseResolverSession

CreateReverseResolverSession creates a session suitable for multiple calls

func DNSRecord

func DNSRecord(client *ethclient.Client, domain string, name string, rrType uint16) (data []byte, err error)

DNSRecord fetches a DNS record

func DNSResolverContract

func DNSResolverContract(client *ethclient.Client, domain string) (resolver *dnsresolver.DNSResolverContract, err error)

DNSResolverContract obtains the resolver contract for a domain

func DNSResolverContractByAddress

func DNSResolverContractByAddress(client *ethclient.Client, resolverAddress common.Address) (resolver *dnsresolver.DNSResolverContract, err error)

DNSResolverContractByAddress instantiates the resolver contract at aspecific address

func DeedContract

func DeedContract(client *ethclient.Client, address *common.Address) (*deed.DeedContract, error)

DeedContract obtains the deed contract at a particular address

func DeedContractFor

func DeedContractFor(client *ethclient.Client, registrar *auctionregistrar.AuctionRegistrarContract, name string) (*deed.DeedContract, error)

DeedContractFor obtains the deed contract for a particular name

func Domain

func Domain(domain string) string

Domain obtains the domain of an ENS name, including subdomains. It does this by removing everything up to and including the first period. For example, 'eth' will return ”

'foo.eth' will return 'eth'
'bar.foo.eth' will return 'foo.eth'

func DomainLevel

func DomainLevel(name string) (level int)

DomainLevel calculates the level of the domain presented. A top-level domain (e.g. 'eth') will be 0, a domain (e.g. 'foo.eth') will be 1, a subdomain (e.g. 'bar.foo.eth' will be 2, etc.

func DomainPart

func DomainPart(domain string, part int) (string, error)

DomainPart obtains a part of a name Positive parts start at the lowest-level of the domain and work towards the top-level domain. Negative parts start at the top-level domain and work towards the lowest-level domain. For example, with a domain bar.foo.com the following parts will be returned: Number | part

 1 |  bar
 2 |  foo
 3 |  com
-1 |  com
-2 |  foo
-3 |  bar

func Entry

func Entry(contract *auctionregistrar.AuctionRegistrarContract, client *ethclient.Client, name string) (state string, deedAddress common.Address, registrationDate time.Time, value *big.Int, highestBid *big.Int, err error)

Entry obtains a registrar entry for a name

func FinishAuction

func FinishAuction(session *auctionregistrar.AuctionRegistrarContractSession, name string) (tx *types.Transaction, err error)

FinishAuction reveals an existing bid on an existing auction

func Format

func Format(client *ethclient.Client, input *common.Address) string

Format provides a string version of an address, reverse resolving it if possible

func InvalidateName

func InvalidateName(session *auctionregistrar.AuctionRegistrarContractSession, name string) (tx *types.Transaction, err error)

InvalidateName invalidates a non-conformant ENS registration.

func LabelHash

func LabelHash(label string) (hash [32]byte)

LabelHash generates a simple hash for a piece of a name.

func NameHash

func NameHash(name string) (hash [32]byte)

NameHash generates a hash from a name that can be used to look up the name in ENS

func NameInState

func NameInState(contract *auctionregistrar.AuctionRegistrarContract, client *ethclient.Client, name string, desiredState string) (inState bool, err error)

NameInState checks if a name is in a given state, and errors if not.

func NewBid

func NewBid(session *auctionregistrar.AuctionRegistrarContractSession, name string, owner *common.Address, amount big.Int, salt string) (tx *types.Transaction, err error)

NewBid bids on an existing auction

func NormaliseDomain

func NormaliseDomain(domain string) string

NormaliseDomain turns ENS domain in to normal form

func Normalize

func Normalize(input string) (output string)

Normalize normalizes a name according to the ENS rules

func Owner

func Owner(contract *deed.DeedContract) (common.Address, error)

Owner obtains the owner of a deed

func PreviousOwner

func PreviousOwner(contract *deed.DeedContract) (common.Address, error)

PreviousOwner obtains the previous owner of a deed

func PublicResolver

func PublicResolver(client *ethclient.Client) (common.Address, error)

PublicResolver obtains the public resolver for a chain

func RegistryContract

func RegistryContract(client *ethclient.Client) (*registry.RegistryContract, error)

RegistryContract obtains the registry contract for a chain

func RegistryContractAddress

func RegistryContractAddress(client *ethclient.Client) (common.Address, error)

RegistryContractAddress obtains the address of the registry contract for a chain

func RegistryContractFromRegistrar

func RegistryContractFromRegistrar(client *ethclient.Client, registrar *auctionregistrar.AuctionRegistrarContract) (*registry.RegistryContract, error)

RegistryContractFromRegistrar obtains the registry contract given an existing registrar contract

func Resolve

func Resolve(client *ethclient.Client, input string) (address common.Address, err error)

Resolve resolves an ENS name in to an Etheruem address This will return an error if the name is not found or otherwise 0

func Resolver

func Resolver(contract *registry.RegistryContract, name string) (common.Address, error)

Resolver obtains the address of the resolver for a .eth name

func ResolverContract

func ResolverContract(client *ethclient.Client, name string) (*resolver.ResolverContract, error)

ResolverContract obtains the resolver contract for a name

func ResolverContractByAddress

func ResolverContractByAddress(client *ethclient.Client, resolverAddress common.Address) (*resolver.ResolverContract, error)

ResolverContractByAddress instantiates the resolver contract at aspecific address

func RevealBid

func RevealBid(session *auctionregistrar.AuctionRegistrarContractSession, name string, owner *common.Address, amount big.Int, salt string) (tx *types.Transaction, err error)

RevealBid reveals an existing bid on an existing auction

func ReverseRegistrarContract

func ReverseRegistrarContract(client *ethclient.Client) (registrar *reverseregistrar.ReverseRegistrarContract, err error)

ReverseRegistrarContract obtains the reverse registrar contract for a chain

func ReverseResolve

func ReverseResolve(client *ethclient.Client, input *common.Address) (string, error)

ReverseResolve resolves an address in to an ENS name This will return an error if the name is not found or otherwise 0

func ReverseResolver

func ReverseResolver(client *ethclient.Client) (*reverseresolver.ReverseResolver, error)

ReverseResolver obtains the reverse resolver contract

func SealBid

func SealBid(name string, owner *common.Address, amount big.Int, salt string) (hash common.Hash, err error)

SealBid seals the elements of a bid in to a single hash

func SetAbi

func SetAbi(session *resolver.ResolverContractSession, name string, abi string, contentType *big.Int) (tx *types.Transaction, err error)

SetAbi sets the ABI associated with a name

func SetDNSRecords

func SetDNSRecords(session *dnsresolver.DNSResolverContractSession, domain string, data []byte) (tx *types.Transaction, err error)

SetDNSRecords sets DNS records

func SetName

SetName sets the name for the sending address

func SetResolution

func SetResolution(session *resolver.ResolverContractSession, name string, resolutionAddress *common.Address) (tx *types.Transaction, err error)

SetResolution sets the address to which a name resolves

func SetResolver

func SetResolver(session *registry.RegistryContractSession, name string, resolverAddr *common.Address) (*types.Transaction, error)

SetResolver sets the resolver for a name

func SetSubdomainOwner

func SetSubdomainOwner(session *registry.RegistryContractSession, name string, subdomain string, ownerAddr *common.Address) (*types.Transaction, error)

SetSubdomainOwner sets the owner for a subdomain of a name

func StartAuction

func StartAuction(session *auctionregistrar.AuctionRegistrarContractSession, name string) (tx *types.Transaction, err error)

StartAuction starts an auction without bidding

func StartAuctionAndBid

func StartAuctionAndBid(session *auctionregistrar.AuctionRegistrarContractSession, name string, owner *common.Address, amount big.Int, salt string, dummies int) (tx *types.Transaction, err error)

StartAuctionAndBid starts an auction and bids in the same transaction.

func State

func State(contract *auctionregistrar.AuctionRegistrarContract, client *ethclient.Client, name string) (state string, err error)

State obains the current state of a name

func Tld

func Tld(domain string) string

Tld obtains the top-level domain of an ENS name

func Transfer

Transfer transfers domain ownership to a new address

Types

This section is empty.

Directories

Path Synopsis
contracts

Jump to

Keyboard shortcuts

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