Skip to Content

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 * as dotenv from 'dotenv'; import { SDK, Pallets } from 'avail-js-sdk'; dotenv.config(); export async function getAccountBalance() { // Initialize SDK with Turing endpoint const sdk = await SDK.New('wss://turing-rpc.avail.so/ws'); // Address to check balance for const address = "5DDY2yzh8uCysYFAiRSTeQVwtZSKNF49CkQkyPH852xvrYKk"; console.log(`Checking balance for address: ${address}`); // Get the current block hash const blockHash = await sdk.client.bestBlockHash(); // Get storage at the current block const storageAt = await sdk.client.storageAt(blockHash); // Fetch account information const accountInfo = await Pallets.SystemStorage.Account.fetch(storageAt, address); // Format balances in AVAIL (dividing by 10^18) const free = accountInfo.value.accountData.free.toString(); const reserved = accountInfo.value.accountData.reserved.toString(); const frozen = accountInfo.value.accountData.frozen.toString(); console.log("The following balances are in the smallest units, divide by 10^18 to get the balance in AVAIL"); console.log(`Free Balance: ${free}`); console.log(`Reserved Balance: ${reserved}`); console.log(`Frozen Balance: ${frozen}`); process.exit(0); } // Execute the function getAccountBalance();
  1. Run the code using:
terminal
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

Fetch account information using a simple curl request via the Subscan API

  1. The Subscan API  can be used to make API queries to the Subscan indexer to make various kinds of queries.
  2. Subscan supports a variety of Substrate-based chains, including Avail DA mainnet and the Turing testnet.
  3. You can either use their publicly available endpoints for the Avail networks, or use a dedicated endpoint .
  4. The examples below use publicly available Subscan API endpoints for both networks.

You need to have curl  installed to run the following examples.

  1. Open a terminal and run the following command:
terminal
curl --location --request POST 'https://avail.api.subscan.io/api/v2/scan/search' \ --header 'Content-Type: application/json' \ --data-raw '{ "key": "<your-avail-address>" }'
  1. Replace <your-avail-address> with the address you want to query.

Sample Response:

JSON response
{ "code": 0, "message": "Success", "generated_at": 1741796675, "data": { "account": { "address": "5HbUMBK8SBKH22qrm2sRDtWNtfyT331tUHpKkFMUKyirkJ6G", "balance": "169389.0977233184983879", "lock": "168914.456888072538284769", "balance_lock": "168914.456888072538284769", "is_evm_contract": false, "account_display": { "address": "5HbUMBK8SBKH22qrm2sRDtWNtfyT331tUHpKkFMUKyirkJ6G" }, "substrate_account": null, "evm_account": "", "registrar_info": null, "count_extrinsic": 0, "nft_amount": "0", "extra": null, "display": "", "web": "", "riot": "", "email": "", "legal": "", "twitter": "", "github": "", "matrix": "", "discord": "", "judgements": null, "reserved": "13000000000000000000", "bonded": "168914456888072538284769", "unbonding": "0", "democracy_lock": "0", "conviction_lock": "0", "election_lock": "0", "staking_info": null, "nonce": 0, "role": "validator", "stash": "5HbUMBK8SBKH22qrm2sRDtWNtfyT331tUHpKkFMUKyirkJ6G", "is_council_member": false, "is_techcomm_member": false, "is_registrar": false, "is_fellowship_member": false, "is_module_account": false, "assets_tag": null, "is_erc20": false, "is_erc721": false, "vesting": null, "proxy": { "proxy_account": [ { "account_display": { "address": "5HmgLcTCi2trnz4AeEiWs4ngAjALu7o4mFnpKdMBnA8jhFnq" }, "proxy_type": "Staking" } ] }, "multisig": { "multi_account_member": [ { "address": "5DfE73hjEYs44JHsuMKzrTMBzkEb6fosaV5xSUEVNjrHwqdB" }, { "address": "5DtGLPULvxXoSPvVv2YZdWmCJy8eEYnWj7MwPpdwGgDnFiua" }, { "address": "5DyHKiRY2ssTWU4CtbbEPoYFmNKaN2X39KRcgb33fnZqk2Yd" } ], "threshold": 2 }, "delegate": null } } }
Last updated on