Content pfp
Content
@
0 reply
0 recast
0 reaction

christopher pfp
christopher
@christopher
Getting the wei balance of a wallet using go-ethereum is easy! All you have to do is: func etherToWei(eth *big.Float) *big.Int { truncInt, _ := eth.Int(nil) truncInt = new(big.Int).Mul(truncInt, big.NewInt(params.Ether)) fracStr := strings.Split(fmt.Sprintf("%.18f", eth), ".")[1] fracStr += strings.Repeat("0", 18 - len(fracStr)) fracInt, _ := new(big.Int).SetString(fracStr, 10) wei := new(big.Int).Add(truncInt, fracInt) return wei; } and then just use the result.
7 replies
1 recast
25 reactions

christopher pfp
christopher
@christopher
actually it's way easier if you get the balance and new(big.Float).Quo(new(big.Float).SetInt(balance), new(big.Float).SetInt(big.NewInt(1e18)))
0 reply
0 recast
6 reactions