Struggling to get correct output logs in console

Hi there, I’m struggling to gather console information on why the getEthNFTOwners function isn’t working in my example

console.log(user.get(“ethAddress”)) and console.log(user.get(“accounts”)) both give back defined, correct results

/** Connect to Moralis server */
const serverUrl = "https://3blwn0stnuyh.usemoralis.com:2053/server";
const appId = "lxHqQdUecmP7HlR6LO3HN1EI9kCvti2zfC4velJC";
Moralis.start({ serverUrl, appId });

/** Add from here down */

async function login() {
    let user = Moralis.User.current();
    if (!user) {
        try {
            user = await Moralis.authenticate({ signingMessage: "Hello World!" })
            console.log(user)
            console.log(user.get("ethAddress"))
        } catch (error) {
            console.log(error)
        }
    }
}
async function logOut() {
    await Moralis.User.logOut();
    console.log("logged out");
}

document.getElementById("btn-login").onclick = login;
document.getElementById("btn-logout").onclick = logOut;

this works as it should, and the console outputs the ethAddress from the current user.

when trying to add a function to get the NFT’s of the user, the console doesn’t spit an error out but its also not capturing the NFT’s, just the ethAddress from the previous function.

Completed code

/** Connect to Moralis server */
const serverUrl = "https://3blwn0stnuyh.usemoralis.com:2053/server";
const appId = "lxHqQdUecmP7HlR6LO3HN1EI9kCvti2zfC4velJC";
Moralis.start({ serverUrl, appId });

async function login() {
    let user = Moralis.User.current();
    if (!user) {
        try {
            user = await Moralis.authenticate({ signingMessage: "Hello World!" })
            console.log(user)
            console.log(user.get("ethAddress"))
        } catch (error) {
            console.log(error)
        }
    }
}
async function logOut() {
    await Moralis.User.logOut();
    console.log("logged out");
}

getEthNFTOwners = async() => {
    const query = new Moralis.Query("EthNFTOwners");
    const EthNFTOwners = await query.find();
    console.log(EthNFTOwners)
}

document.getElementById("btn-login").onclick = login;
document.getElementById("btn-logout").onclick = logOut;

Thanks!

here it looks like you try to query the db, you can run that code directly in your browser console for easier debugging

do you have data in that table in db? what doesn’t work?

1 Like