Linking wallets to users

Hi everyone,

for my app I allow users to sign up using the email/password option. I am now trying to use the link functionality to link wallets to these users. I was wondering if someone can explain how you would go about adding a new wallet (and verifying that this user has access to this wallet) by for example using the useWalletConnect component to allow users to select a wallet and sign into a variety of wallets. However I do not want this to create a new user/session in my Moralis db I want to instead link these wallets to the email/password using the Link functionality. Can someone explain how this can be done?

2 Likes

you use .link instead of .authenticate, you need to know the eth address at the time you want to use .link, and .link will ask the user to sign a message in order to validate that he really has the wallet

Hey I am using React Native. So do you know how I would somehow pass useWalletConnect() to the .link function in order for the user to be able to validate that they own said address?

I’m thinking that you need to find what is the ETH Address for the user and then pass it as a parameter to .link and it should work same way as .authenticate works after that regarding the validation

Hey having the same issue.

Trying something like this:

const wallet_connect = async () => {
      await Moralis.Web3.link(MY_ADDRESS)
}

But then I get this error “Error: Non ethereum enabled browser”.

maybe you need to enable web3 before, and you could try Moralis.link

you could get that error if you also don’t start a local http server to open your html file

Hey thanks so much for the help.

So enabling seems to work fine, it’s opening wallet connect and giving me a message to connect. But the Moralis.link is giving me the same “Non ethereum enabled browser” Error.

const wallet_connect = async () => {
      console.log("enabling")
      await Moralis.enable({connector})
      console.log("connecting")
      await Moralis.link(MY_ADDRESS)
    }

Looking into the local http server possibility but I’m very new to this. Not really understanding how that works with a react native app?

maybe you need to provide connector as parameter to link too

Just tried it, still no luck.

This is the signature:

static link: (account: string, options?: LinkOptions) => Promise<User>;

The connector doesn’t seem like it could be a LinkOptions

yes, it doesn’t looks like there is a connector parameter after looking in the code either, it looks like it should get the web3 instance from what was set previously by enableWeb3

So something like this?

const wallet_connect = async () => {
      console.log("enabling")
      await Moralis.enable({connector})
      .then(value => {
        console.log("connecting")
        Moralis.link(value)
      })
    }

Doesn’t seem to work either. link definitely wants a string. But getting the same “Non ethereum enabled browser” Error actually. If that means anything. Maybe link isn’t even getting to the point where the parameter is needed?

you are using the latest version of Moralis SDK, right?

you can get current version with Moralis.CoreManager.get("VERSION")

Looks like 0.0.99.
I’m using the etherium react native boiler plate. Here are the packages: https://github.com/ethereum-boilerplate/ethereum-react-native-boilerplate/blob/main/package.json

current version seems to be: 0.0.182

I see, okay i’ll upgrade and see if that changes anything!