elishambadi
elishambadi

Reputation: 31

How can I connect Flutter Crossplatform app (mobile and web) to Metamask?

I've been trying for a while to connect Flutter App to Metamask wallet, but most packages are only for one platform either mobile or web.

I've tried installing Metamask and WalletConnect_dart packages, but their issues are as below.

Metamask package is only for web: https://pub.dev/packages/metamask

WalletConnect package is for connecting your own wallet: https://pub.dev/packages/walletconnect_dart

I'd like to connect to wallet then send and sign transactions using web3dart. Kindly assist!

Upvotes: 3

Views: 637

Answers (1)

rmtmckenzie
rmtmckenzie

Reputation: 40493

So there's a few issues here. The first is that Metamask is more of a service than just a wallet as far as I can tell. So when you're interacting with it, it's not going to be as a wallet but rather as a consumer of their services. As such a package such as walletconnect_dart probably won't help much unless they explicitly support Metamask.

The metamask package linked to unfortunately doesn't really seem to do most of what is actually intended with the metamask SDK as you noted only supports the web (barely, at time of writing), so it's not going to be much help either.

There are packages that might be able to help such as webthree, but they might not provide for all the functionality that metamask has.

If webthree isn't sufficient, this probably isn't what you want to hear, but if you want to create a mobile app using metamask you're probably stuck with two main options:

  1. You can ask the metamask team to support flutter by creating a dart SDK. This is probably a bit of a long-shot as flutter is likely not a huge priority, but they may consider it if you create a ticket and get some support behind you.
  2. Create a plugin yourself supporting whichever platforms you need. This is a non-trivial project as it would involve looking at the SDKs for iOS and Android (and potentially js for web if you want to support that as well), figuring out a common API that could be used across all the platforms, then exposing that through from native code on each platform to dart (I'd recommend pigeon if you do go this route). This would require some understanding of kotlin/java and swift/objc, as well as how the communication channels between dart and the native platforms work. You may be able to offload some operations from the SDK to dart code, but anything cryptography-related is probably better off done through the SDKs.

This could be a medium to large challenge depending on your experience with native coding on iOS and Android, but is not impossible.

Upvotes: 0

Related Questions