GetBalance returns the wei balance of the given account.
(client *ethclient.Client, key *keystore.Key)
| 299 | |
| 300 | // GetBalance returns the wei balance of the given account. |
| 301 | func GetBalance(client *ethclient.Client, key *keystore.Key) (balance *big.Float, err error) { |
| 302 | wei, err := client.BalanceAt(context.Background(), key.Address, nil) |
| 303 | if err != nil { |
| 304 | return |
| 305 | } |
| 306 | |
| 307 | balance = new(big.Float) |
| 308 | balance.SetString(wei.String()) |
| 309 | balance = balance.Quo(balance, big.NewFloat(math.Pow10(18))) |
| 310 | |
| 311 | return |
| 312 | } |