Greetings,
I have been working on playing around with my own version of the wallet dapp that is featured in the How to Build a Web Wallet in 10 Minutes tutorial and had a question about customizing the ERC20 token balance displays. I’m building this wallet to partner with another dapp that I am working on that will utilize a custom token that we deployed on Polygon. I want this wallet to only show the user their balance for the single token that is relevant. I tried editing the getTokenBalances options to add the contract address, but that seemed to break it. Right now, as is, it will fetch and display all of the ERC20 tokens that I have in my wallet on Polygon, so all I need to be able to do is filter those results down to the single token I care about.
I would appreciate it a lot if someone out there could help me understand how to filter these tokens properly. Maybe I just don’t understand how to properly utilize the getTokenBalances options.
Here is the relevant bit of code from my main.js file:
getERC20Balances = async () => {
let ethTokens = await Moralis.Web3API.account.getTokenBalances();
let maticTokens = await Moralis.Web3API.account.getTokenBalances({chain: 'matic'});
let otherBalancesContent = document.querySelector('#otherBalances');
otherBalancesContent.innerHTML ='';
if(ethTokens.length > 0){
}
if(maticTokens.length > 0){
let tokenBalanceContent = '';
maticTokens.forEach((e,i) => {
let content = `
<tr>
<td>${e.name}</td>
<td>${e.symbol}</td>
<td>${(e.balance / ('1e' + e.decimals))} </td>
<td>${e.decimals}</td>
<td>${e.token_address}</td>
</tr>
`
tokenBalanceContent += content
});
otherBalancesContent.innerHTML += tokenBalanceContent;
}
}
Thanks in advance for your help and please let me know if there is more information I need to share to add better context.