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!