umbracle / ethgo

Ethereum Golang API
https://www.ethgoproject.io
Mozilla Public License 2.0
484 stars 134 forks source link

go mod tidy error #181

Closed greyireland closed 2 years ago

greyireland commented 2 years ago

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)
ferranbt commented 2 years ago

go get github.com/ethereum/go-ethereum

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

greyireland commented 2 years ago

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

ferranbt commented 2 years ago

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.

greyireland commented 2 years ago

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
)
ferranbt commented 2 years ago

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.

greyireland commented 2 years ago

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~

ferranbt commented 2 years ago

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.

chappjc commented 2 years ago

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:

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