[SOLVED] Issues with Phantom Wallet Login + Show wallet address

Hello Moralis world

First of all, let me say thank you for creating this platform, it makes life for a developer/enthausiast so much easier.

Hower I do have a couple issues in the code i used from Moralis. I am trying to activate 2 options

  1. log in with Phantom Wallet
  2. show Phantom Wallet Address after login.

Issues:

  • I am able to login with the Phantom Wallet but it doesn’t work 100% bulletproof. It seems like I am able to login once without issues and then either I keep logged in, even after refresh or just nothing happens when clicking on Connect Wallet.

  • When I try to show the adddress via a code I found on Moralis, I get “undefined” on my screen

image

Here is my code:

HTML:

button id=“btn-login” class=“sc-button header-slider style style-1 wallet fl-button pri-1” style=“width: 80%; height: 50%; display: block; margin-left: 7%; margin-top: 5%;”>Connect Wallet

button id=“btn-logout” class=“sc-button header-slider style style-1 wallet fl-button pri-1” style=“width: 80%; height: 50%; display: block; margin-left: 7%; margin-top: 5%;”>Disconnect Wallet

JAVASCRIPT:

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

script>

    *// connect to Moralis server*

    const serverUrl = "https://ci6niblk6bbl.usemoralis.com:2053/server";

    const appId = "y9ljzA94d2j44gorSyURoiNH3ZnkkaGPwSYZEyt3";

    Moralis.start({ serverUrl, appId });

    // add from here down

    async function login() {

        let user = Moralis.User.current();

        if (!user) {

            user = await Moralis.authenticate({ type: 'sol' }).then(function (user) {

                console.log(user.get('solAddress'))

            });

        }

    }

    async function logOut() {

        await Moralis.User.logOut();

        console.log("logged out");

    }

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

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

/script>

script>

    Moralis.User.currentAsync().then(function (user) {

        var wallet = user.get('ethAddress');

        document.getElementById('WalletAddressHere').innerHTML = wallet

    });

/script>

did you look in db to see if the right ethAddress is there?

if the address is in Users table for that user, then you should be able to get it from user object.

you can use console.log(user) to see what is there

if you are refering to the debug console/output in visual studio, it just stays empty. But I must say, I’m a webdeveloper first so all this is kind of new for me. it would be better for us to have someone who can take a look at our code and fix these things against a economical rate


you can join Discord and post in đŸ€”job-offers-hire-devs channel

1 Like

thanks, will do! do you see any errors in my code? Except for the fact that I have no idea how to see if the eth address is being get

I see solAddress and ethAddress in different places in code

that did it! thanks man! :slight_smile:

addtional question: do you know how I can make sure this shows immediately? Now i still have to refresh and sometimes when I try to test, I am already logged in :confused:

What to display automatically? If you are already logged in than you can get the address from current user object

i figured it out via using log on/log off buttons, all good :slight_smile:
one last question for you sir: is this phantom wallet connect already available via mobile? When I try to log on via mobile it doesn’t do anything, it only works on desktop.

I don’t know exactly about mobile

Hi Cryptokid! We got our wallet connect to work successfully but it still doesn’t do anything on mobile
 Do you have any news about this or could you ask someone relevant about this? I can’t find any of it online except the WalletConnect, which will completely take over the login-flow