MoralisWeb3 = serverUrl = “://w6j9c9lnnoio.usemoralis.com:2053/server”; //Server url from moralis.io
MoralisWeb3 = appId = “wZsf07rYLfsPudepzTdjvrAsYfgWAQb0BFbnTFJI”; // Application id from moralis.io
async function initializeApp() {
** hideElement(userInfo)**
** await Moralis.start({ serverUrl, appId });**
** await Moralis.enableWeb3();**
** currentUser = Moralis.User.current();**
** if (!currentUser){**
** currentUser = await Moralis.Web3.authenticate();**
}
initUser = async () => {
** if (await Moralis.User.current()) {**
** hideElement(userConnectButton);**
** showElement(userProfileButton);**
** }else {**
** showElement(userConnectButton);**
** hideElement(userProfileButton);**
** }**
}
login = async () => {
** try {**
** await Moralis.Web3.authenticate();**
** initUser();**
** } catch (error) {**
** alert(error)**
** }**
}
logout = async () => {
** await Moralis.User.logOut();**
** hideElement(userInfo)**
** initUser();**
}
openUserInfo = async () => {
** user = await Moralis.User.current();**
** if (user){**
** showElement(userInfo);**
** }else{**
** login();**
** }**
}
hideElement = (element) => element.style.display = “none”;
showElement = (element) => element.style.display = “block”;
const userConnectButton = document.getElementById(“btn-login”);
userConnectButton.onclick = login;
const userProfileButton = document.getElementById(“userInfo”);
userProfileButton.onclick = openUserInfo;
const userInfo = document.getElementById(“userInfo”);
document.getElementById(“btn-CloseUserInfo”).onclick = () => hideElement(userInfo);
document.getElementById(“btn-logout”).onclick = logout;
document.getElementById(“userInfo”).style.display = “none”;
}
initializeApp();