6

I want to add feature in my mobile app to send ether from one address to another address and for this I need to integrate metamask with my flutter mobile application. What package can I use for this purpose? I want to send ether through metamask but using UI of my application.

How can I do this?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Rehan
  • 131
  • 1
  • 8

4 Answers4

6

I implemented this in my app. Here's the code. Hope this helps I have used the walletconnect_dart package to open the wallet from where the user can connect their wallet to the app and url_launcher to open the wallet

Future<void> connectWallet() async {
    final connector = WalletConnect(
      bridge: 'https://bridge.walletconnect.org',
      clientMeta: const PeerMeta(
        name: 'any name',
        description: 'any description',
        url: 'any url',
        icons: [
          'logo url'
        ],
      ),
    );

    // Subscribe to events
    connector.on('connect', (session) {
      debugPrint("connect: " + session.toString());

      address = sessionStatus?.accounts[0];
      chainId = sessionStatus?.chainId;

      debugPrint("Address: " + address!);
      debugPrint("Chain Id: " + chainId.toString());
    });

    connector.on('session_request', (payload) {
      debugPrint("session request: " + payload.toString());
    });

    connector.on('disconnect', (session) {
      debugPrint("disconnect: " + session.toString());
    });

    // Create a new session
    if (!connector.connected) {
      sessionStatus = await connector.createSession(
        chainId: 137, //pass the chain id of a network. 137 is Polygon
        onDisplayUri: (uri) {
          AppMehtods.openUrl(uri); //call the launchUrl(uri) method
        },
      );
    }
  }
mr.SoSerious
  • 121
  • 1
  • 9
  • 1
    I've implemented this but this is just for connecting to wallet and getting accounts. How can I do transactions? For example transfering usdt from wallet to another wallet address. I see everywhere people use web3dart but it is for interacting with contract! I just need to do a simple transfer why this should be so ridiculuosly hard to achieve in Flutter? – Davoud Feb 19 '23 at 06:56
1

We are actively maintaining a flutter template for creating web3 mobile apps: https://github.com/Nuxify/Sophon

The template uses walletconnect_dart and web3_dart and also got an example when connecting, reading, and writing to a Goerli smart contract.

  • I already connected to Metamask and got the accounts! How to do transfer usdt from wallet to another wallet? I don't want to interact with smart contract and put private key inside code. I want user accept transaction through Metamask. – Davoud Feb 19 '23 at 07:00
  • HI there. I installed the Sample app from the playstore and metamask login is not working – ravi Jun 30 '23 at 15:38
0

In flutter, there is web3dart that works for mobile app

https://github.com/simolus3/web3dart

In react, there is moralis

https://github.com/MoralisWeb3/react-moralis

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 13 '22 at 08:59
0

Metamask supports WalletConnect protocol so you can use walletconnect_dart package to connect your app to Metamask wallet and then use the same package to sign/send transactions signed by Metamask.

Tom
  • 1,516
  • 1
  • 14
  • 34
  • Can you share how to transfer and sign with metamask in android app! using this package. I can connect to wallet but have problem transfering USDT in BNB chain. – Davoud Feb 25 '23 at 11:13
  • You have to use `provider` from `walletconnect_dart`. Have a look at the example app either for `walletconnect_dart` package or for Ethereum example you can check out my package `walletconnect_qrcode_modal_dart`. – Tom Mar 01 '23 at 10:16