Im using the boilerplate code and when I log in I have access to the moralis object, but how can i use moralis outside the login function?
async function login() {
let user = Moralis.User.current();
if (!user) {
try {
user = await Moralis.authenticate({ signingMessage: "Hello " })
const userAddress = user.get('ethAddress')
document.getElementById("user").innerHTML = userAddress;
// get BSC native balance for a given address
const options = {chain: "bsc",address:userAddress}
const balance = await Moralis.Web3API.account.getNativeBalance(options);
const uBalance = balance['balance']
document.getElementById('balance').innerHTML = ubalance;
console.log(balance)
} catch(error) {
console.log(error)
}
}
}
But how can I run this function on a button click?
Since this fucntion is outside the login function
async function getNFT(){
const userAddress = user.get('ethAddress')
const option = { q: "Pancake", chain: "bsc", filter: "name", address:userAddress };
const NFTs = await Moralis.Web3API.account.getNFTs(option);
console.log(NFTs)
}
Since its outside the login function I cant use moralis stuff, like user.get