Can someone let me know where i am going wrong here ?
// main.js
const serverUrl = "https://tfnpgrbijuyl.usemoralis.com:2053/server";
const appId = "GZkY9b1x6psaRSiuAyoPI7aC13HZxwIZGRpSvig0";
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!" })
await Morlais.enableWeb3();
console.log(user);
console.log(user.get('ethAddress'));
} catch(error) {
console.log(error)
}
}
}
async function logOut() {
await Moralis.User.logOut();
console.log("logged out");
}
async function approve() {
let options = {
contractAddress: "0x31E5066dBf561b5d57B6711029fCfF1a158cf086",
functionName: "handleApproval",
abi: [{
"inputs": [
{
"internalType": "contract IERC20",
"name": "_token",
"type": "address"
},
{
"internalType": "uint256",
"name": "_numTokens",
"type": "uint256"
}
],
"name": "handleApproval",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}],
params:{
_token: "0x0000000000000000000000000000000000001010",
_numTokens: "100"
},
msgValue: Moralis.Units.ETH()
}
await Moralis.executeFunction(options);
}
document.getElementById("btn-login").onclick = login;
document.getElementById("btn-logout").onclick = logOut;
document.getElementById("btn-approve").onclick = approve;