I need a feature of converting values from ether to wei and vice-versa. I've tried to find some in go-eth modules, but didn't find anything.
I should also notice, that we (I don't actually understand why) have no web3 implementation in golang.
In any cases everyone said, that "you should use go ethereum for interacting with ethereum in go"
But go-ethereum with comparsion to web3 is not really comfortable to use, because it's missing some usefull tools such this simple thing -- converting ethereum values. (and also it's much more complex interaction with events than in web3)
I don't understand, why everyone else, who interact with ethereum in python, java-script, java and other languages have this convinient tools, but not golang developers.
More than that - in other languages web3 implementations are pretty simple, and they have similar functions for any implementation in any language.
But if I need to build something in go, I have to use go-ethereum, which have completly different (and more complex)syntax, and many usefull functions I need is just don't exist.
So current situation is looked...so sad!
So please, I ask you to make lives of go developers a bit better and gave us at least this particular feature
Hey @JackBekket take a look at https://github.com/ethereum/go-ethereum/blob/master/params/denomination.go. I disagree that interaction with contracts is trickier in golang compared to web3. You can use abigen to quickly generate bindings for your smart contracts that basically do all event handlings and interactions for you. If you have the need for particular features that web3 has, that we do not provide, please open another issue. We're happy for all feedback we get!
func etherToWei(val *big.Int) *big.Int {
return new(big.Int).Mul(val, big.NewInt(Ether))
}
func weiToEther(val *big.Int) *big.Int {
return new(big.Int).Div(val, big.NewInt(Ether))
}
If you don't want to loose fractions of an ETH to truncating (I don't have that much money to loose 0.x ETHs)
Better use:
````go
import "params"
func weiToEther(wei *big.Int) *big.Float {
return new(big.Float).Quo(new(big.Float).SetInt(wei), big.NewFloat(params.Ether))
}
````
The etherToWei is also affected but i don't have time now and only need weiToEther
Most helpful comment