web3swift icon indicating copy to clipboard operation
web3swift copied to clipboard

Authenticate with a wallet (e.g. Metamask)

Open armanarutiunov opened this issue 3 years ago • 11 comments
trafficstars

From what I understand this library allows you to create or import a wallet via mnemonics or the private key. But is it possible to somehow authenticate with a wallet similar to the way you do it on web? So that the app can read your wallet but the moment you want to fire a transaction you have to approve it in the actual wallet app separately?

Importing a wallet via private key makes sense if it's a wallet app. But what I'm trying to build is a frontend for a smart contract. And potential users of such app would not trust their private keys or mnemonics with it.

armanarutiunov avatar Mar 20 '22 01:03 armanarutiunov

MetaMask suggests using wallet for such a connection: https://docs.walletconnect.com/mobile-linking https://docs.metamask.io/guide/mobile-best-practices.html#using-walletconnect

pharms-eth avatar Mar 20 '22 22:03 pharms-eth

Hi. Looks like you want walletconnect functionality.

There is no such feature yet. I'd be more than happy to merge a PR adding this feature, it seems like it would be useful for sure 👍

skywinder avatar Apr 02 '22 10:04 skywinder

Probably we will add WC as a module to web3swift in the future. Let me discuss it with the team.

skywinder avatar Apr 02 '22 10:04 skywinder

Hi. Looks like you want walletconnect functionality.

There is no such feature yet. I'd be more than happy to merge a PR adding this feature, it seems like it would be useful for sure 👍

That'd be a great feature. I recently did something similar using WC as you suggest. I'm going to get familiar with the code to see if I can help out :)

maurovz avatar Apr 21 '22 18:04 maurovz

I would like this feature as well, let me know if I can help !

Benoye avatar Apr 23 '22 13:04 Benoye

Sounds amazing, thank you! Let me also know if there is any help needed. Can't wait!

armanarutiunov avatar Apr 23 '22 18:04 armanarutiunov

Hi guys, I looked at how something could be done quickly. I managed to get it to work, here is my process:

1 - connect to a wallet using the WallectConnectSwift library 2 - prepare an EthereumTransaction using this library 3 - convert the EthereumTransaction object to a Client.Transaction object of the WalletConnect library 4 - Open the Wallet Connect url to make the appropriate wallet app open and approve the transaction

This way, it is not necessary to have the private key to launch transactions. As you can see, in this process this library is used only as a helper to prepare the transactions..

Benoye avatar Apr 25 '22 14:04 Benoye

Nice one @Benoye! I think you probably want to use the V2 library though: https://github.com/WalletConnect/WalletConnectSwiftV2 The one you shared a link for works only with the V1 of their protocol as I understand.

armanarutiunov avatar Apr 25 '22 14:04 armanarutiunov

Good point @armanarutiunov ! Thanks ! I did not know there was a v2 ! I am going to take a look in the following days..

Benoye avatar Apr 25 '22 14:04 Benoye

Probably we will add WC as a module to web3swift in the future. Let me discuss it with the team.

Every needs this, trust me I been telling wallet connect the whole time. @skywinder

wyfii avatar Apr 26 '22 06:04 wyfii

Nice one @Benoye! I think you probably want to use the V2 library though: https://github.com/WalletConnect/WalletConnectSwiftV2 The one you shared a link for works only with the V1 of their protocol as I understand.

I talked on Discord with some WalletConnect people: some wallets are not supported yet in the v2 protocol, I am going to stuck to the v1 as I want to put something in production quickly..

Benoye avatar Apr 26 '22 08:04 Benoye