WalletConnect provider

upgrade moralis module to the last.

add authentiticated option { provider: “walletconnect” }

and get error

TypeError: MWalletConnectProvider.default is not a constructor

How make it worked in react?

Hi,

Can you please elaborate your question.

Please follow these guidelines to post on the forum so that we can assist you better! FAQ - Common Issues & How To Get Help

Please paste your code as much as possible. And also screenshots to provide reference.

Thank you. :slight_smile:

Thank you.
I think Codesandbox will be ok.
to check the problem and help to fix it…

Hi @DmKodOff ,

Did you only try running on the Codesandbox? Codesandbox will not have the providers injected by the plugin wallets.

So, when I ran the react project and opened in my browser, the login functionality worked as expected.

Please do let me know. Looking forward to your response. :slight_smile:

I got a similar error in my local react app. Maybe I did not correct injected the Wallet Connect provider. How do you do it in your project? Can you send screen, or code, please)

@malik Can you make Pull Request to the https://github.com/MoralisWeb3/demo-apps/tree/main/moralis-react-app
to show how correct inject WalletConect provider in react for Moralis. Maybe just add one more button - “login with WalletConnect”. it will be very Apretiated.

1 Like

I am looking into it as we speak. Will get back to you very soon.

Hi @DmKodOff,

Yes, there was an issue with the WalletConnect Provider in the Moralis sdk which caused issues when using it with React.

We have fixed this bug and it will be pushed in 0.0.28 version.

Thank you for supporting and pointing these issues out. Really appreciate it. Have a wonderful day sir. :slight_smile:

1 Like

Hi @malik ,
Thank you for fix it.
Kindly looking forward to upgrading the “moralis-react” module to include the WC provider at auth method, at least…
Do you have any idea when it can happen?

Hi, @malik,

I just create a pull request for react-moralis to add the WalletConnect Provider to authenticate()
Can you check it)

Looking at it right now. Thanks.

Hi @DmKodOff,

[email protected] is published so you can install it directly now.

Until this PR is merged, You can try to achieve it this way –

import React, { useState } from "react";
import ReactDOM from "react-dom";
import Moralis from "moralis";

Moralis.initialize("5yzecM1asSKvvuJeiVr7HrssT3ma4hmLRXIalQZx");
Moralis.serverURL = "https://6l9rj93oy21e.moralis.io:2053/server";

const initialUser = Moralis.User.current();

const App = () => {
  const [user, setUser] = useState(initialUser);
  const onLoginW = async () => {
    //Change made here
    const user = await Moralis.Web3.authenticate({ provider: "walletconnect" });
    setUser(user);
  };

  const onLoginM = async () => {
    const user = await Moralis.authenticate();
    setUser(user);
  };
  const onLogout = () => {
    Moralis.User.logOut();
    setUser(null);
  };
  if (user) {
    return <button onClick={onLogout}>Logout</button>;
  }
  return (
    <>
      <button onClick={onLoginM}>Login Metamask</button>
      <button onClick={onLoginW}>Login WalletConnect</button>
    </>
  );
};

ReactDOM.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>,
  document.getElementById("root")
);

This should get you moving with the functionality. :slight_smile:

1 Like

Hi, @malik.

Thank you.

I got the 0.28 already. It works properly. thanks.

I use the react-moralis user provider in the project, but there doesn’t provide any method for setUser in react state, there only setUserData(), but it not will help on it.(.

Could you elaborate more on what you mean. If it’s regarding another issue of react-moralis, you can create another thread as this thread is titled WalletConnect. As always please provide all the information necessary for us to properly evaluate what you’re looking for.

Have a great day. :slight_smile:

You now can use walletconnect with the latest release of react-moralis by providing:
provider:'walletconnect' to the authenticate and/or enable function.

3 Likes

Thank you. It’s worked well.)

3 Likes