Hello! When I open my code with LiveServer I get the following error:
Uncaught ReferenceError: Moralis is not defined
at main.js:4
Im not 100% sure why it isnt working. I have added 'defer; to my script tag in JS. Thank you! (:
Here is the js file:
/** Connect to Moralis server */
const serverUrl = "https://XYZ";
const appId = "ABC";
Moralis.start({ serverUrl, appId });
async function init(){
await Moralis.initPlugins();
await Moralis.enableWeb3();
await listAvailableTokens();
}
async function listAvailableTokens(){
const result = await Moralis.Plugins.oneInch.getSupportedTokens({
chain: 'eth',
});
const tokens = result.tokens;
let parent = document.getElementById("token_list");
for( const address in tokens){
let token = tokens[address];
let div = document.createElement("div");
div.className = "token_row";
let html = `
<img class="token_list_img" src="${token.logoURI}">
<span class="token_list_text">${token.symbol}</span>
`
div.innerHTML = html;
parent.appendChild(div);
}
}
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)
}
}
}