Skip to main content
Version: 0.6

Get the Account balance of any ERC20 or ERC777 Token on the Aventus Network

Returns the balance of a specific token for a given AvN account.

await API.query.getTokenBalance(account, token_address);

Example

const AVN_API = require("avn-api");
//Replace the endpoint_url with the url received from Aventus.
const AVN_GATEWAY_URL = "<endpoint_url>";
const API = new AVN_API(AVN_GATEWAY_URL);

const ACCOUNT = "5DAgx...";
const TOKEN_ADDRESS = "0x7e5bb...";

async function main() {
await API.init();

let token_balance = await API.query.getTokenBalance(ACCOUNT, TOKEN_ADDRESS);
console.log(token_balance);
}

(async () => {
await main();
})();

Example Result

5100000000000000000000

JSON-RPC

REQUEST
POST https://AVN-API-URL/query

HEADERS
Content-Type: application/json Authorization': bearer <awtToken>

REQUEST PARAMS

  • accountId [required] - a string representing the public key or SS58 address of the account to check for token balance.
  • token [required] - a hex string representing the token ID (20 bytes) of the token being checked.

JSON-RPC Example

curl https://AVN-API-URL/query \
-X POST \
-H "Content-Type: application/json" \
-H "Authorization: bearer <awtToken>" \
-d '{"jsonrpc":"2.0", "method":"getTokenBalance", "params":{"accountId":"5DAgxVxK...DdMr", "token":"0x2adce...b9480e"}, "id":1}'
result - string integer value of the current token balance for the account in its smallest denomination

Example Output

{
"jsonrpc": "2.0",
"id": 1,
"result": "5100000000000000000000"
}