Populate table problem (BSC programming tutorial)

Hello guys i have a quick qzestion regarding a table im trying to populate, following daniels video about BSC programming (full course).
this is the error im getting when i click the button that should populate the table (leaderboard)

this is a part of the functions of the code

async function populate(){
      const name = await Moralis.Web3API.account.getTokenBalances({chain: chainToQuery}).then(buildLeaderboardTable);

    function buildLeaderboardTable(data){
     document.getElementById("resultLeaderboard").innerHTML = 
      `<table class ="table table-dark table-striped" id="leaderboardTable">
      const table = document.getElementById("leaderboardTable");
      const rowHeader = `<thead>
          <th>Last Seen</th>
      table.innerHTML += rowHeader

      for(let i = 0; i < data.length; i++){
        let row = 
        table.innerHTML +=row;

note that for testing purposes im just starting to get a token name in of my balances, down the line i want to populate it with other elements from the backend that will be fed into it from my game dapp. Anyhow - what am i missing exactly to avoid the error?

thank you!

for this in order to make, without giving the address as parameter, you’ll have to be authenticated and when you are authenticated it will use the eth address of current user

thank you for the response. the thing is the function populate(); is run upon the launch of the app like so:

function launchApp(){
alert("not logged in")
}else {
populate ();

so it would work or what am i missing exactly? than you once again @cryptokid

do you get there the ETH Address of current user?

what you get if you run directly in your browser console:

name = await Moralis.Web3API.account.getTokenBalances({chain: 'bsc'})

from logs it looks like "chain":"binance testnet", was tried, and for address the entire user object

Yes useradress is shown via console.log.
If i type in

name = await Moralis.Web3API.account.getTokenBalances({chain: 'bsc'})

in the browser it throws:

@cryptokid it does throw it either with chain: "bsc" or chain: "bsc testnet"

what if happens if you use:

name = await Moralis.Web3API.account.getTokenBalances({chain: ‘bsc testnet’, address: user.get(“ethAddress”)})

unfortunately this
Screen Shot 2021-11-30 at 1.47.55 PM

it may be because of quotes, you could delete those " and write new ones

word. that was it!
so i changed it to this now but it still would not populate the table for some reason.

maybe you can call that buildLeaderboardTable function explicitly with the result of the function

what do you mean with that, putting the buildLeaderboardTable function right into the populate function?

I mean something like:

async function populate(){
      const name = await Moralis.Web3API.account.getTokenBalances({chain: chainToQuery}).then(buildLeaderboardTable);


async function populate(){
      const name = await Moralis.Web3API.account.getTokenBalances({chain: chainToQuery})

thank you! this worked. i also had a mistake further up in the code that i didnt show in this thread. it had to do with the ID of a div as well.

Anyway bare with me for one moment: obviously i dont need tokenbalances for a leaderboard. What i would actually need is at least these 3 columns

address i think i can get right but how do i get individually added columns like score or username in this function? It is part of the leaderboard object in the moralis data base seen like so:
Screen Shot 2021-11-30 at 2.34.37 PM

Would it be something like
Moralis.Web3API.account.get(Leaderboard, score) or how do you do it?

Thank you so much

you can write console.log(JSON.stringify(user)) to see what data you have there
you may have all you need in that user object

hmm it just shows me some information but not really what im looking for.

is there an option for custom functions like to retrieve extended objects / columns and rows?

you can query directly the User class to see what info you get that way

this is the general documentation for queries:

1 Like

thanks @cryptokid im looking at the documentation right now. will get back to you if i need some more guidance.