Connecting multiple web3 wallets

I would like to implement passwordless login with email to the overall application but also allow users to connect their wallets (Metamask, Flow, Layer2 etc) in order to interact with their respective blockchains. Is this possible with Magic? Ideally this would work similar to an Oauth flow (e.g. linking your Twitter or Facebook accounts).

Additionally, if the same user has multiple wallets, does Magic treat these as separate users?

3 Likes

Hi there Melissa,

Yes, you can have have Magic as one form of login and offer another wallet like MetaMask as another form of login similar to oasis.app. We have support for Flow, you can learn more here. And for Layer 2 on Ethereum, you can explor Matic or BSC. Here are a few guides that can help:

To your second question, if the user signed up with email and other social logins, they will have two different wallets. For any EVM-compatible chains, you can use the same address for multiple chains like Ethereum, BSC, Matic, Fantom, and etc.

Thanks! To clarify, I was wondering if you can connect multiple accounts to the same user (e.g. connect both Metamask and Binance Smart Chain). I basically want the user to be able to log in through a familiar passwordless flow and then have options for them to link their wallets without creating a new user.

Thank you for clarifying. I was wondering if you knew that Magic comes with a wallet under the hood?

Also, are you wanting to use Magic only for auth? If so, then you will need to establish a mapping between the user’s id (via Magic) and the user’s MetaMask public address. You’ll need to use web3 personal sign to prove that the user is the owner of the public address.

Last question on “multiple accounts to the same user (e.g. connect both Metamask and Binance Smart Chain)”, were you referring to BSC as a wallet / account?

you will need to establish a mapping between the user’s id (via Magic) and the user’s MetaMask public address

How is this done? Is this referenced in the docs? To clarify, it’s not possible to prove that user owns a Metamask public address using Magic without creating a new user.

Last question on “multiple accounts to the same user (e.g. connect both Metamask and Binance Smart Chain)” , were you referring to BSC as a wallet / account?

Yes I’m referring to a BSC wallet/account.

1 Like

How is this done? Is this referenced in the docs?

Yes, it is referenced in our docs here.

To clarify, it’s not possible to prove that user owns a MetaMask public address using Magic without creating a new user.

Are you referring to creating a new user with Magic or MetaMask?

If you want to use Magic only for auth, so that the user can log in through a familiar passwordless flow, and then once they’ve logged in, have options for them to link to their existing wallets, it is possible. You’ll just need to establish the mapping.

OK thanks for the answers to my questions! Excited to build on Magic!

2 Likes

Hello @seemcat,

I’m quite new to this and I want to implement something similar. I want to allow users to use the already created wallet by Magic or to use their linked wallet (MetaMask for example). I don’t really understand what do we need to sign and why.

Thank you so much for your help.

1 Like

Hi there Eduard!

Really cool to hear that you’re implementing something similar. I’m currently OOO, so I’ve reached out to my team to help you out when they’re back in the virtual office.

Until then, can you please confirm the following:

  • Have you read our Magic x Polygon or BSC Guides yet that I’ve linked up there?
  • Can you please clarify what you’re new to? Are you new to building a dapp or just this specific feature?

Thanks!

1 Like

Hello!

Thank you for your response while being OOO, very appreciated. Hopefully, someone from the team will help me with this.

I’m new to building dapps. I saw all the tutorials (both Polygon and BSC) and I understand how to change between networks. But, like Melissa, I want to always login with Magic and when logged in, the platform makes the user choose between the already created wallet address from Magic or to link to another wallet like MetaMask. What I don’t understand quite well is the part of the mapping between the user’s id (Magic) and the user’s MetaMask public address.

  • Why should I need to use web3 personal sign?
  • Where should I sign?
  • And what information is needed to be signed with this method?

Again, thank you all for your help.

Hey @edmbn,

@seemcat was describing a use case for triggering the user to sign an arbitrary message to prove ownership of the external (Metamask) wallet they are trying to connect to their Magic account. You’d want to have this check in place before saving that connection in your DB to prove ownership of that other wallet - otherwise users could theoretically try to connect any ethereum address, although without them actually owning it, that would serve no purpose.

After triggering a signature, you can use an ecRecover function to prove the signature was in fact made by the private key that corresponds to the public address.

Resources:
ecRecover - web3.eth.personal — web3.js 1.0.0 documentation

Hello @hcote,

Thank you for helping me understand this. So If I understood well this is just in case you want to save, for example on a database, that the Magic Link user owns a MetaMask public address, right? So you would sign a message with the MetaMask private key and later on check if ecRecover returns the public address of the MetaMask linked wallet, right?

Correct - if you want to save the address to your DB you’ll want to verify ownership of the external wallet address. And for this you’d only need to verify it using the ecRecover once, before saving it to your DB