umbracle/ethgo

go mod tidy error

Closed this issue · 8 comments

go get github.com/ethereum/go-ethereum

run go mod tidy ,get this error

github.com/ethereum/go-ethereum/crypto imports
        github.com/btcsuite/btcd/btcec/v2/ecdsa tested by
        github.com/btcsuite/btcd/btcec/v2/ecdsa.test imports
        github.com/btcsuite/btcd/chaincfg/chainhash: ambiguous import: found package github.com/btcsuite/btcd/chaincfg/chainhash in multiple modules:
        github.com/btcsuite/btcd v0.21.0-beta (/Users/crx/go/pkg/mod/github.com/btcsuite/btcd@v0.21.0-beta/chaincfg/chainhash)
        github.com/btcsuite/btcd/chaincfg/chainhash v1.0.0 (/Users/crx/go/pkg/mod/github.com/btcsuite/btcd/chaincfg/chainhash@v1.0.0)

go get github.com/ethereum/go-ethereum

What are you trying to do? This is not the go-ethereum repo.

I want to use both libraries, go Ethereum and ethgo, but their dependencies conflict

Do you have a repo to reproduce this? Which version of Go are you using? I tried it on a test repo and it does work.

main.go

package main

import (
	"github.com/ethereum/go-ethereum/common"
	"github.com/ethereum/go-ethereum/crypto"
	"github.com/ethereum/go-ethereum/log"
	"github.com/umbracle/ethgo"
	"github.com/umbracle/ethgo/jsonrpc"
)

func main() {
	crypto.CreateAddress2(common.HexToAddress(""), [32]byte{}, nil)
	log.Debug("hello")
	_ = ethgo.HexToAddress("0x000")
	_, _ = jsonrpc.NewClient("")
}

go.mod

module github.com/greyireland/ethgo-demo

go 1.15

require (
	github.com/ethereum/go-ethereum v1.10.17
	github.com/google/go-cmp v0.5.6 // indirect
	github.com/umbracle/ethgo v0.1.0
	golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
)

I reproduced it. It happens when using the crypto package in Geth since we both import btcd package but with different versions (Geth uses a newer one). I will check if it is worth it the update.

On the meantime, you can use version v1.10.16 of Geth which uses the same library as ethgo.

If you can't guarantee compatibility with the latest Ethereum, it's difficult for newcomers to use it.
So it is worth it the update~

It seems to be some type of dependency error being tracked here. I tried a couple of iterations without success. I will wait for some possible PRs on the geth side.

What are you trying to do with the library that requires interactions with go-ethereum? Ideally, it is a full replacement and you do not need both at the same time.

The following is a crummy solution, but the only thing that seems to get past the "ambiguous import" error caused by the github.com/btcsuite/btcd/chaincfg/chainhash module that also exists as the chaincfg/chainhash package in the github.com/btcsuite/btcd module (two different modules providing the same package import path, hence the issue), is all of the following:

  • specify go 1.17 in go.mod
  • include require github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 // indirect to disambiguate
  • go mod tidy -compat=1.17

It seems that when the chainhash module was created for use in the new btcec/v2 module, this problem wasn't anticipated.