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 AvnApi = require("avn-api");
const GATEWAY = "<endpoint_url>"; //Replace the endpoint_url with the url received from Aventus.
const api = new AvnApi(GATEWAY);
const account = "5DAgx...";
const token_address = "0x7e5bb...";
async function main() {
await api.init();
// Returns the account token balance.
await api.query.getTokenBalance(account, token_address);
console.log();
// "30"
}
(async () => {
await main();
})();
Example Output
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
EXAMPLE
## JSON-RPC over HTTPS POST
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":"5DAgxVxKmnJ7hfhDEB9UetZm4jR2MPjGZGrmJZjirSVJDdMr", "token":"0x2adce7ada36d86253aa63bcf4aad9f84ccb9480e"}, "id":1}'
RESULT FIELDS VALUE - string integer value of the current token balance for the account in its smallest denomination
BODY
{
"jsonrpc": "2.0",
"id": 1,
"result": "30"
}