Running an async function on click onboardButton.onclick = async () to prompt Metamask wallet login and once the user logs in I run an spinner and load some additional info for the user, but I get an uncaught not defined error on the async function at the then section
Code section follows:
onboardButton.innerText = "Connect MetaMask!";
spinner.classList.add('hidden');
notConnected.classList.remove('hidden');
notConnected.classList.add('show-not-connected');
onboardButton.onclick = async () => {
// CODE RUNS OK UNTIL HERE, IT LOADS METAMASK POP-UP
await window.ethereum
.request({
method: "eth_requestAccounts",
});
// CODE BREAKS HERE, USER CAN INPUT PASSWORD AND CONNECT ITS METAMASK, IT FINISHES CONNECTION, I GET ACCOUNT ADDRESS BACK AND SLICE OK, BUT APP BREAKS.
then(function (accts) {
onboardButton.innerText = `✔ ...${accts[0].slice(-4)}`;
notConnected.classList.remove('show-not-connected');
notConnected.classList.add('hidden');
spinner.classList.remove('hidden');
onboardButton.disabled = true;
window.address = accts[0];
accounts = accts;
window.contract = new web3.eth.Contract(abi, contractAddress);
loadInfo();
});
};
}
};



