miguelmota / go-ethereum-hdwallet

Ethereum HD Wallet derivations in Go (golang)

Home Page:https://github.com/miguelmota/go-ethereum-hdwallet

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how get balance from wallet ?

Phuong39 opened this issue · comments

how get balance from wallet ?

Use the ethclient available from go-ethereum for reading data from chain or for doing any chain interactions, since reading balances is out-of-scope for this package.

Example

package main

import (
	"context"
	"fmt"
	"log"
	"math"
	"math/big"

	"github.com/ethereum/go-ethereum/common"
	"github.com/ethereum/go-ethereum/ethclient"
)

func main() {
	client, err := ethclient.Dial("https://mainnet.infura.io")
	if err != nil {
		log.Fatal(err)
	}

	account := common.HexToAddress("0x71c7656ec7ab88b098defb751b7401b5f6d8976f")
	balance, err := client.BalanceAt(context.Background(), account, nil)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(balance) // 25893860171173005034
}

Hope this helps!