Query balances on Avail DA

Setting up the dev environment

In this guide we will use Avail's dedicated SDKs to interact with the Turing testnet. To set up a dev environment for the SDK of your choice, please follow the steps outlined here.

Querying the balance of an account

To query basic information about an account, including it's balance, you need to call the system_account extrinsic from the system pallet on an Avail node.

  1. Inside your-file-name.ts, add the following code:
avail-js
import { SDK } from "avail-js-sdk"
 
const main = async () => {
  const providerEndpoint = "wss://turing-rpc.avail.so/ws"
  const sdk = await SDK.New(providerEndpoint)
 
  const key = "5DDY2yzh8uCysYFAiRSTeQVwtZSKNF49CkQkyPH852xvrYKk"
  const value: any = await sdk.api.query.system.account(key)
 
  console.log(value.toHuman())
  const freeBalanceInAvail = Number(value.data.free.toString()) / Math.pow(10, 18)
  console.log(`Free balance: ${freeBalanceInAvail} AVAIL`)
 
  process.exit()
}
 
main()
  1. Run the code using:
ts-node your-file-name.ts

Your response should look something like this:


Sample Response:
{
  nonce: '109',
  consumers: '2',
  providers: '1',
  sufficients: '0',
  data: {
    free: '1,000,000,000,000',
    reserved: '100,000,300,000,000,000,000',
    frozen: '100,000,000,000,000,000,000',
    flags: '170,141,183,460,469,231,731,687,303,715,884,105,728'
  }
}
Free balance: 28.3046577073 AVAIL