Metamask is not being launched after clicked the Moralis launch button

Try to replace

</main>

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

with

</main>

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

Nope, simply isnā€™t openning the metamask or doing anything else, but no errors

okā€¦
try this then: <script src="main.js" ></script>

1 Like

it was that

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

now it worked. Thanks

it worked by changing to <script src="main.js" ></script>

1 Like

Now it authenticate but the USER object is not being created and stored automatically in Moralis server, the User row in the table remains in 0, like all the rest.
What am I missing?

console.log('hello world');

// connect to Moralis server

Moralis.initialize("OVQv4GzkGYKOJmcd2UE0wF6AGh4Czz6Vlq6Sfzn8");

Moralis.serverURL = "https://krkxhau0hur3.usemoralis.com:2053/server";

login = async () => {

    await Moralis.authenticate().then(async function (user) {

        console.log('logged in')

        user.set("name", document.getElementById('user-name')).value;

        user.set("email", document.getElementById('user-email')).value;

    await user.save();

    })

}

document.querySelector('#btn-login').onclick = login;


You should see users added even after you only authenticate with MetaMask. Are you sure you are looking at the right Moralis server dashboard?

Yes, is the only Server I have set by now. Iā€™m following the tutorial step by step.
I set it to ā€œtestnetā€, so now Iā€™m using Rinkeby testnet, but I changed into Ganache but itā€™s still not showing anything in Moralis Dashboard

This is the error Iā€™m getting in the code with Moralis.Initialize()

Ignore it. If you correctly provided SDK import in html it will work correctly.

Iā€™ve just tried to signup on your server. Do you see my user object?

Yes, the new user object appeared

In the Signin.html I used <script src="main.js" ></script> to connect it with the main.js where the Moralis SDK connection is, I think

You can try it yourself:

Let me know how it will work for you

I tried it, I logged in there, it lets me authenticate with Metamask but no new user showing up in the Moralis Server, there still your User as the only user.
It seems everything is working as you could logged in but there is something my code or my connection with the Moralis server. I tried changing browser to Brave and Firefox but no change

Are you trying to log in with data inputed? How does it work if you specify email and name?

Yes Iā€™ve tried both just clicking on the button directly and by inputting the username and email, in both cases triggers Metamask, it lets me sign and thatā€™s it.
No change in the server

Marcel could you please share over here the code you used to fix the Metamask issue? I havenā€™t checked my error so I havenā€™t fixed yet. Thanks in advance!

Iā€™m trying to build a nft videogame for a friend and connect his marketplace with metamask, any advice or recommended docs to check?

Btw, thanks for developing this tool, this saves us tons of hours and headaches to non-coders.

Hi Billyb,

Iā€™ve just started with Moralis and I had the same issue as you - button was unresponsive and didnā€™t open Metamask. To solve I kept my original code (I wrote it all out as I find it better for learning personally) and then copy and pasted the code in the tutorial into a new .html file and ran that - it ran perfectly. I ran through each line (in VS Code you can split the screen to show 2 code docs at the same time) to make sure everything matchedā€¦ my issue was in

                let user = Moralis.User.current();
                if(!user) {
                    user = await Moralis.authenticate();
                }
                console.log("Logged in user:", user);

I didnā€™t capitalise the ā€œUā€ in Moralis.User.current - changing that worked for me. If you apply a similar approach for your code you may find the issue. If youā€™re still having an issue let me know and Iā€™ll test your code tomorrow - unfortunately I need to run out right now, just thought Iā€™d jump in and try and help you quickly.

Hope this helps you resolve the issue though. :slight_smile:

1 Like

So how is your final Login object version? like this?

login = async () => {

    let user = Moralis.User.current();

    if(!user) {

    user = await Moralis.authenticate();

    }

    console.log("Logged in user:", user);

    user.set("name", document.getElementById('user-name')).value;

    user.set("email", document.getElementById('user-email')).value;

    await user.save();

    window.location.href = "dashboard.html";

    }

My code worked in the console when using both

window.location.href = "signin.html";

and

window.location.href = "dashboard.html";

and finally the server dashboard added the new user, but only by using the console, it hasnā€™t worked by clicking the button, and also hasnā€™t worked to jump from signin.html to the dashboard.html after authenticating with Metamask. It only works using the console manually

I tried your code like that but is not working either

Hi Marcel,

Does the below code run for you:

<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("ENTER APP ID");
            Moralis.serverURL = "ENTER 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>

That should work for you after you enter your server and app ID. if it doesnā€™t the next thing I would try is to open the page in Chrome with no active extensions except Metamask. I have found that sometimes Chrome extensions can cause a number of issues with web pages - and as a dev I like to turn off as many as I can when debugging. If it does work for you without any other extensions then you can turn on each one, one by one and keep testing until you find the one causing an issue.

Other than that Iā€™m not really sure, as I say Iā€™m still new to Moralis but if I come across anything further down the line that might help Iā€™ll let you know.

2 Likes