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_ETHEREUM_ADDRESS);
important
You can get the AVN_GATEWAY_URL here.
- Example
- Example Result
- JSON-RPC
- JSON-RPC Output
const { AvnApi, SetupMode, SigningMode } = require("avn-api");
const AVN_GATEWAY_URL = "gateway url of your chosen network"
const options = {
suri: "suri of your account",
setupMode: SetupMode.SingleUser,
signingMode: SigningMode.SuriBased,
};
const ACCOUNT = "5DAgx...";
const TOKEN_ETHEREUM_ADDRESS = "0x7e5bb...";
async function main() {
await avnSdk.init();
const api = await avnSdk.apis();
let token_balance = await api.query.getTokenBalance(ACCOUNT, TOKEN_ETHEREUM_ADDRESS);
console.log(token_balance);
}
(async () => {
await main();
})();
5100000000000000000000
REQUEST
POST https://AVN_GATEWAY_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_GATEWAY_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
{
"jsonrpc": "2.0",
"id": 1,
"result": "5100000000000000000000"
}