Metamask wont log in

hello everyone

im having a really aggravating problem I’m on the e the dex JavaScript tutorial and im getting the following error

Uncaught (in promise) Error: Cannot execute Moralis.enableWeb3(), as Moralis Moralis.enableWeb3() already has been called, but is not finished yet

this is my code

// connect to Moralis server

      const serverUrl = "*********";
      const appId = "****************";
      Moralis.start({ serverUrl, appId });



     // add from here down
     async function login() {
      let user = Moralis.User.current();
      if (!user) {
        user = await Moralis.authenticate();
      }
      console.log("logged in user:", user);
    }

    async function logOut() {
      await Moralis.User.logOut();
      console.log("logged out");
    }

    document.getElementById("btn-login").onclick = login;
    document.getElementById("btn-logout").onclick = logOut;


async function getTop10tokens() {
    const response = await  fetch (' https://api.coinpaprika.com/v1/ ');
    const tokens  =  await response.json();

    return tokens.filter( token => token.rank <= 10).map(token => token.symbol);

}

async function gettickerdata() {
    const response  = await fetch ('https://api.1inch.exchange/v3.0/137/tokens');
    const tokens =  await response.json ();
    const tokenlist = object.values(tokens.tokens);

    return tokenlist. filter(token => tickerlist.includes(token.symbol));

}

getTop10tokens()
    .then(gettickerdata)
    .then(console.log);

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


        <!-- Moralis SDK code -->
        <script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
        <script src="https://unpkg.com/moralis/dist/moralis.js"></script>
    <title>Moralis Dex </title>

</head>


<body>
    
    
    <button id="btn-login">Moralis Login</button>
    <button id="btn-logout">Logout</button>


    <script src="./dex.js"></script>

</body>
</html>

what am i doing wrong? its connecting too metamask but it wont log in. metamask shows up as a blank login

Change this to the latest src url and try again

    <script src="https://unpkg.com/moralis@latest/dist/moralis.js"></script>

still getting the error

Are you able to open metamask manually or is it just loading?

If you are able to open metamask manually, then try to run this line in the browser console and see if opens the metamask.
await Moralis.authenticate()

I was able to recreate the error by running the authenticate again when the metamask is open.
So don’t click the login button twice.
await Moralis.authenticate()

where would i run that code?

thats what meta mask looks like when i click login

You need to unlock your metamask and confirm the process to login

how do i unlock meta mask?

The metamask popup is asking for your password which you need to enter to unlock it, then you can connect afterwards

i went in and put my password

its still giving me the following error

Uncaught (in promise) Error: Cannot execute Moralis.enableWeb3(), as Moralis Moralis.enableWeb3() already has been called, but is not finished yet

so after refreshing the code a few times and signing in its doing what its supposed too do. thank you everyone for taking time too answer and help me :slight_smile: i love this community

1 Like