MetaMask is not opening

<html>
    <head>
        <script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
        <script src="https://unpkg.com/moralis/dist/moralis.js"></script>
    </head>
    <body>
        <h1>Gas Stats With Moralis</h1>

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

        <script>
            //connect to Moralis Server
            Moralis.initialize("xxx");
            Moralis.serverURL = "https*sserver*/server";

            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;
        </script>
    </body>
</html>

Why is not connecting to metamask. when i click on moralis login nothing happens

this is an older syntax, now you have to use this syntax:

        serverUrl = "https://asfasdf:2053/server"
        appId =  "gfgsfgfg" 
        Moralis.start({ serverUrl, appId});

instead of the above two lines.

You can also look in your browser console to see if there are any errors.

Hi @prof.finance

Also take a look at https://docs.moralis.io/misc/troubleshooting#uncaught-in-promise-error-non-ethereum-enabled-browser

still everything is blank, no resposne from metamask

Please check your console :man_factory_worker:

it says
Uncaught SyntaxError: Unexpected token โ€˜asyncโ€™

Can you paste your current html version?

> 
> <html>
>     <head>
>         <script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
>         <script src="https://unpkg.com/moralis/dist/moralis.js"></script>
>     </head>
>     <body>
>         <h1>Gas Stats With Moralis</h1>
> 
>         <button id="btn-login">Moralis Login</button>
>         <button id="btn-logout">Logout</button>
> 
>         <script>
>             //connect to Moralis Server
>             serverUrl = "https://asasasas.usemoralis.com:2053/server"
>             appId =  "asasas"
>             Moralis.start({ https://asasasas.usemoralis.com:2053/server,appid});
> 
>             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;
>         </script>
>     </body>
> </html>

this code would work fine if you would use this syntax:

        serverUrl = "https://asfasdf:2053/server"
        appId =  "gfgsfgfg" 
        Moralis.start({ serverUrl, appId});

instead of what you used

you may need to hit logout before login if you are already logged in.

where exactly are you asking me to put this code?

instead of this?

this is the code that looks strange, what you pasted looks fine, you donโ€™t have to change anything there, I tested you code with that line modified and it worked fine

same issue man UwU

i copy pasted your code

use this code:


<html>
    <head>
        <script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
        <script src="https://unpkg.com/moralis/dist/moralis.js"></script>
    </head>
    <body>
        <h1>Gas Stats With Moralis</h1>

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

        <script>
            //connect to Moralis Server
        serverUrl = "https://asdfasdfadf:2053/server"
        appId =  "agasdgasdgag" 
            Moralis.start({ serverUrl, appId});

            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;
        </script>
    </body>
</html>

same UwU, hahah no idea whats going on

can you share a print screen of what you have?

ok, did you read this part?

short version, youโ€™ll have to open that html with a local web server, not directly in the browser as a file