wealdtech / go-ens

Apache License 2.0
90 stars 33 forks source link

Issue building app using go modules #6

Closed deiu closed 3 years ago

deiu commented 3 years ago

When trying to build a newly started project using go modules, I get some issues coming out from go-ens.

To replicate, you can take the example from the README file and put it in a new file (e.g. main.go) sitting in an empty dir. Next you init the go modules.

$ go mod init
$ go mod tidy

Next, I try to run go build ./...:

$ go build ./...
# github.com/wealdtech/go-ens/contracts/dnsresolver
../../../../pkg/mod/github.com/wealdtech/go-ens@v1.0.0/contracts/dnsresolver/dnsresolver.go:23:6: undefined: abi.U256
# github.com/wealdtech/go-ens/contracts/deed
../../../../pkg/mod/github.com/wealdtech/go-ens@v1.0.0/contracts/deed/deed.go:23:6: undefined: abi.U256
# github.com/wealdtech/go-ens/contracts/auctionregistrar
../../../../pkg/mod/github.com/wealdtech/go-ens@v1.0.0/contracts/auctionregistrar/auctionregistrar.go:23:6: undefined: abi.U256
# github.com/wealdtech/go-ens/contracts/registry
../../../../pkg/mod/github.com/wealdtech/go-ens@v1.0.0/contracts/registry/registry.go:23:6: undefined: abi.U256
# github.com/wealdtech/go-ens/contracts/reverseresolver
../../../../pkg/mod/github.com/wealdtech/go-ens@v1.0.0/contracts/reverseresolver/reverseresolver.go:23:6: undefined: abi.U256
# github.com/wealdtech/go-ens/contracts/reverseregistrar
../../../../pkg/mod/github.com/wealdtech/go-ens@v1.0.0/contracts/reverseregistrar/reverseregistrar.go:23:6: undefined: abi.U256
# github.com/wealdtech/go-ens/contracts/resolver
../../../../pkg/mod/github.com/wealdtech/go-ens@v1.0.0/contracts/resolver/resolver.go:23:6: undefined: abi.U256

Output of generated go.mod:

module github.com/deiu/test

go 1.14

require (
    github.com/ethereum/go-ethereum v1.9.18
    github.com/wealdtech/go-ens v1.0.0
)

Here is the output of go version:

$ go version
go version go1.14.6 linux/amd64
deiu commented 3 years ago

I have managed to find and resolve the issue. It turns out I needed to import the v3 version of go-ens, which is a bit different than the example in the README. A good rule of thumb is to always import the package currently defined for go-ens in go.mod, which in this case is module github.com/wealdtech/go-ens/v3.

For those looking for a fix, you need to do this in the example:

package main

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

....