Im using this code here:
async function populate(){
const balances = await Moralis.Web3API.account.getTokenBalances({chain: "bsc"}).then(buildTableBalances);
}
function buildTableBalances(data){
document.getElementById("resultBalances").innerHTML = `<table class="table table-dark table-striped" id="balancesTable">
</table>`;
const table = document.getElementById("balancesTable");
const rowHeader = `<thead>
<tr>
<th>Token</th>
<th>Symbol</th>
<th>Balance</th>
</tr>
</thead>`
table.innerHTML += rowHeader;
for (let i=0; i < data.length; i++){
let row = `<tr>
<td>${data[i].name}</td>
<td>${data[i].symbol}</td>
<td>${data[i].balance/10**18}</td>
</tr>`
table.innerHTML += row
}
}
But this version sucks because I have to divide the balances with 10**18, but not all token have 18 decimals.
I need a way to make this dynamic for evvery token , some have 9, some have 6 decimals and so on, but in the populate function when I do
console.log(balances, i get nowhere the decimals