Skip to main content

How to get account balance

This recipe demonstrates how to fetch an FT4 account balance using an EVM key pair. This is essential for checking asset balances before performing transfers or for displaying account information in applications.

Prerequisites

  • Node.js
  • FT4 client: npm install @chromia/ft4
  • Postchain client: npm install postchain-client

Demo script

Key Features

This recipe includes examples for:

  • FT4 balance queries - Using the getBalanceByAccountId function for specific assets
  • EVM key integration - Working with EVM key pairs to resolve FT4 accounts
  • Asset-specific balances - Querying balances for particular assets (e.g., CHR)
  • Account resolution - Converting EVM keys to FT4 account identifiers

Balance Query Process

The recipe follows this workflow:

  1. Create keystore - Initialize an EVM keystore with your private/public key pair
  2. Resolve accounts - Use the keystore interactor to find associated FT4 accounts
  3. Create connection - Establish an FT4 connection to the blockchain
  4. Query balance - Call getBalanceByAccountId with account ID and asset ID

Common Use Cases

This pattern is useful for:

  • Wallet applications - Displaying current asset balances to users
  • Payment validation - Checking sufficient funds before transfers
  • Portfolio tracking - Monitoring asset holdings across accounts
  • Exchange integrations - Validating account balances for withdrawals

Requirements

  • Registered EVM key - Your EVM key must be registered on the target blockchain
  • FT4 account - An associated FT4 account must exist for the EVM key
  • Asset ID - The hex-encoded asset ID you want to query (e.g., CHR asset ID)

Learn more