0

How to define async? I try to declare async = require('async') and no success. Then I try on terminal: npm install async --save and same thing without result.

async function donate() {

  let options = {
    contractAddress: "0x..",
    functionName: "newDonation",
    abi: [{ ....
    }],
    params: {
      note: "Thanks from Mr. Popcorn!"
    },
    msgValue: Moralis.Units.ETH(0.2)
  }
  await Moralis.executionFunction(options);
}


async function login() {
  let user = Moralis.User.current()

  if (!user) {
    try {
      user = await Moralis.authenticate({
        signingMessage: `
                Authenticate to popcorn!
                
                Please make sure to understand the terms.
    
                `
      })
      await Moralis.enableWeb3()
      console.log(user.get('ethAddress'))

      document.getElementById("popcorn").innerHTML = `
                <p>Wallet: ${user.get('ethAddress')}</p>
                <p><button id="donate_btn" onclick=${donate}>Donate</button></p>            
                `;

    } catch (error) {
      console.log(error)
    }
  }
}

async function logOut() {
  await Moralis.User.logOut()
  console.log("Logged out!")
}

document.getElementById("login_btn").onclick = login;
document.getElementById("logout_btn").onclick = logOut;
Ivar
  • 6,138
  • 12
  • 49
  • 61
Brolosse
  • 39
  • 3

1 Answers1

-1

try this and let me know if its work.

document.getElementById("login_btn").onclick = function(){
  return login()
}
document.getElementById("logout_btn").onclick = function(){
  return logOut()
}
mahdi ashori
  • 515
  • 4
  • 13
  • Thanks so lot for your tips, but It still does not work. I try with var async = require('async'); and var _ = require('lodash'); ....but same thing.... and finaly, I try npm install async --save. – Brolosse Jun 19 '22 at 19:34