Fetch balances and other information for an account
Query the balances and many other informational points for an account on Avail DA
On-chain name of method: system_account
Parameters
parameter
type
optional
description
address
SS58
true
The account address to fetch information for
Returns
nonce: Current nonce of the account on Avail DA
consumers: The number of other modules that currently depend on this account's existence. The account cannot be reaped until this is zero
providers: The number of other modules that allow this account to exist. The account may not be reaped until this is zero.
sufficients: The number of modules that allow this account to exist for their own purposes only. The account may not be reaped until this is zero.
free: Amount of Transferrable AVAIL tokens with the account
reserved: Amount of AVAIL tokens that are not bonded, but also not yet freely available
frozen: Amount of AVAIL tokens currently staked by the account
flags: Some extra information about the account
Note
NONCE
Every account on Avail DA starts with a nonce value of 0. This number represents
the number of transactions executed on Avail DA by that particular account.
Every successive transaction will have a nonce value that is incremented by 1 from the previous transaction.
To extend this a bit further, the sum of all non-zero nonces on Avail DA will be equal to the total number of transactions executed on Avail DA.
Minimal example (Fetch account information for a single account)
Note
You will need to set up the dev environment required to run this example.
For instructions, check out our docs here.
If you're sending an extrinsic (i.e conducting a transaction) you will need to replace the demo seed phrase with your own seed phrase.
The rest of the code should work as is.
Inside your-file-name.ts, add the following code:
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}`); console.log("Account information fetched successfully"); process.exit(0);}// Execute the functiongetAccountBalance();