Querying Balances
Import the common
package:
import (
"github.com/PhoenixGlobal/Phoenix-Chain-SDK/libs/common"
)
Query the balance of an account at the latest block:
account := common.HexToAddress("0xF35F4545fa03416C4ABb9FC9c743EDa6e35c5592")
latestBalance, err := client.BalanceAt(context.Background(), account, nil)
if err != nil {
log.Fatal(err)
}
fmt.Println(latestBalance)
You can also query the balance of an account at a certain block height:
blockNumber := big.NewInt(21879393)
account := common.HexToAddress("0xF35F4545fa03416C4ABb9FC9c743EDa6e35c5592")
balance, err := client.BalanceAt(context.Background(), account, blockNumber)
if err != nil {
log.Fatal(err)
}
fmt.Println(balance)
Last updated