Retrieve token balance
How to retrieve the balance of a token for a wallet
Introduction
To fetch the balance of a certain token for a wallet, you need to call the function getTokenBalance
which will return a promise containing a TokenBalance
object. If you need the entire balance a certain wallet holds, it is recommended to use the getTokenBalances
function.
Function:
venlyConnect.api.getTokenBalance("<WALLET_ID>", "<TOKEN_ADDRESS>");
venlyConnect.api.getTokenBalanceByAddress("<SECRET_TYPE", "<WALLET_ADDRESS>", "<TOKEN_ADDRESS>");
Example:
const venlyConnect = new VenlyConnect('YOUR_CLIENT_ID');
venlyConnect.api.getTokenBalance("c8ec9954-fa1a-4682-9cf8-ef5c1015d1d1","0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0").then((tokenBalance) => {
console.log("The balance of",tokenBalance.symbol,"is",tokenBalance.balance);
})
Returns:
{
tokenAddress: "0xab7950c514d156ea506090da62ffa1f6915efd6a",
rawBalance: "50000000000000000000",
balance: 50,
decimals: 18,
symbol: "IFT",
logo: "https://logos.covalenthq.com/tokens/43113/0xab7950c514d156ea506090da62ffa1f6915efd6a.png",
type: "ERC20",
transferable: true,
name: "Infinity Test Token",
exchange: {
usdBalanceValue: 0
}
}
JS Fiddle Example
Function Reference
The function reference describes the different functions that are available in the Widget. For each function you can find the signature, its parameters, and possible options documented.
Updated 12 days ago