Phoenix Chain SDK Doc
  • Introduction
  • Client
    • Initializing a Client
  • Accounts
    • Querying Balances
  • Blocks and Transactions
    • Querying Blocks
    • Querying Transactions
  • Smart Contracts
    • Installing Dev Tools
    • Generating Go Contracts File
    • Deploying Contracts
    • Querying Contracts
    • Writing to Contracts
  • Event logs
    • Filtering Event logs
    • Subscribing to Event Logs
Powered by GitBook
On this page
  1. Accounts

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)
PreviousAccountsNextBlocks and Transactions

Last updated 2 years ago