Visual studio issue

Hello everyone. I am here to build a Dex via moralis and iā€™ll be coding the UI using HTML, CSS/Bootstrap and JavaScript.

https://xbr6mqradtof.moralis.io:2053/server

I have managed to managed to setup Moralis and have the code on Visual studio and have the page hosted in my browser. I also have ā€˜live serverā€™ installed.
However, when I right-click to bring up ā€˜Click on live serverā€™ this does not show in the window and so when I click on ā€˜moralis loginā€™ nothing happens.

Can anyone help?

Thanks

Hi,

Could you please paste your code and any errors that you were facing while executing this code.

Looking forward to your response.

Thanks.

Hello Malik. Thanks for reaching out. The code below is copied from the Moralis setup.

When I hover over ā€˜index.htmlā€™ I have an error saying ā€˜Problems in this fileā€™ which I am looking into now.

Thanks

Gas Stats With Moralis

Moralis Login

Logout

Sorry, I need to format the code a minute


<html>

<head>

  <!-- 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>

</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(6bQeg1LjiujEARMEBsH8oQfHDC4hVCBpSmGAhLhm);

    Moralis.serverURL = https://xbr6mqradtof.moralis.io:2053/server;

     // add from here down

      async function login() {

        let user = Moralis.User.current();

        if (!user) {

          user = await Moralis.Web3.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>

Hello Malik, It seems to be working now. I basically installed another version of the ā€˜live serverā€™ and clicked on the ā€˜open serverā€™ at the bottom of the screen. Metamask opens up ok now.

Thanks for a speedy response tho :slight_smile:

1 Like

Oh thatā€™s great.

Happy BUIDling! :smiley:

lolā€¦ok, spoke to soon. Something is very temporamental as it wonā€™t work now. Iā€™ll have a play about. Iā€™ll get back in touch if no joy.

Thanks

Ok, all good. 3 hours later lol.

1 Like

Hello, Could someone help at all. The code below is as follows. Metamask does not load upon clicking login. It wouldnā€™t work, then it did work and now will not work again.


<html>

<head>

  <!-- 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>

</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 (6bQeg1LjiujEARMEBsH8oQfHDC4hVCBpSmGAhLhm);

    Moralis.serverURL = https://xbr6mqradtof.moralis.io:2053/server;

     async function login() {

        let user = Moralis.User.current();

        if (!user) {

          user = await Moralis.Web3.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>

Something seems wrong with my application ID, as i get error messageā€¦ā€œAn identifier or keyword cannot immediately follow a numeric literal.javascriptā€

I also did not use the SERVERLESSWEB3 invite code as i signed up and then saw it. I donā€™t know if this should make a difference although it was obviously put there for a reason!!

1 Like

Hello @ProjekP

I changed your code a bit. Everything should work fine now.

<!DOCTYPE html>
<html>

<head>

  <!-- 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>

</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
    init = async () => {
      window.web3 = await Moralis.Web3.enable();
    };

    Moralis.initialize("Application ID");

    Moralis.serverURL = "serverURL";

    login = async () => {
      try {
        await Moralis.Web3.authenticate();
        let user = Moralis.User.current();
        console.log("logged in user:", user);
      } catch (error) {
        console.log(error);
      }
    };

    logOut = async () => {

      await Moralis.User.logOut();

      console.log("logged out");

    }

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

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

    init();
  </script>

</body>

</html>

Hope this helps. :slight_smile:

Happy BUIDLing! :smiley:

1 Like

Hello Yomoo, thanks for reaching out. However, I still have the same problem. When I hover over index.html in my browser it says ā€œThere are 2 problems in this fileā€ They both relate to my server URL and app ID.

When I hover over my app ID in the program, I still get this error messageā€¦An identifier or keyword cannot immediately follow a numeric literal.javascript.

Are you sure you inserted them correctly?

Moralis.initialize("hhshash2j2jj");
Moralis.serverURL = "https://fjjj23j4j2.moralis.io:2053/server";

Excellent. I inserted the speech marks although I tried this laso yesterday on the original code and nothing happened which is why I left them out whilst attempting to debug. However, your code works nice and efficient. Thank you very much to you. Good evening/day :smile:

1 Like

Thatā€™s great :muscle:

Happy to help! :smiley:

1 Like

Hi,

Can anyone tell me where to find the GoLive icon in visual studio? I did an update and although LiveServer is installed, the icon is gone from the bottom of the screen?

Thanks

Squash that. I just rebooted. All good thanks.

1 Like