WalletConnect is an open source protocol for connecting decentralised applications to mobile wallets with QR code scanning or deep linking.

Overview

pub.dev Effective Dart Stars Issues MIT License

WalletConnect is an open source protocol for connecting decentralised applications to mobile wallets with QR code scanning or deep linking. A user can interact securely with any Dapp from their mobile phone, making WalletConnect wallets a safer choice compared to desktop or browser extension wallets.

Introduction

WalletConnect connects mobile & web applications to supported mobile wallets. The WalletConnect session is started by scanning a QR code (desktop) or by clicking an application deep link (mobile).

WalletConnect-Dart-SDK is a community SDK and port of the official WalletConnect-monorepo.

⚠️ At the moment, only Algorand is supported!

WalletConnect lets you build:

  • Decentralized web applications and display QR codes with qr_flutter
  • Mobile dApps with deep linking using url_launcher
  • Cross-platform wallets

Once installed, you can simply connect your application to a wallet.

// Create a connector
final connector = WalletConnect(
    bridge: 'https://bridge.walletconnect.org',
    clientMeta: PeerMeta(
      name: 'WalletConnect',
      description: 'WalletConnect Developer App',
      url: 'https://walletconnect.org',
      icons: [
        'https://gblobscdn.gitbook.com/spaces%2F-LJJeCjcLrr53DcT1Ml7%2Favatar.png?alt=media'
      ],
    ),
);

Usage

Dapps

Initiate connection

// Create a connector
final connector = WalletConnect(
    bridge: 'https://bridge.walletconnect.org',
    clientMeta: PeerMeta(
      name: 'WalletConnect',
      description: 'WalletConnect Developer App',
      url: 'https://walletconnect.org',
      icons: [
        'https://gblobscdn.gitbook.com/spaces%2F-LJJeCjcLrr53DcT1Ml7%2Favatar.png?alt=media'
      ],
    ),
);

// Subscribe to events
connector.on('connect', (session) => print(session));
connector.on('session_update', (payload) => print(payload));
connector.on('disconnect', (session) => print(session));

// Create a new session
if (!connector.connected) {
    final session = await connector.createSession(
        chainId: 4160,
        onDisplayUri: (uri) => print(uri),
    );
}

Sign transaction

// Set a default walletconnect provider
connector.setDefaultProvider(AlgorandWCProvider(connector));

// Sign the transaction
final txBytes = Encoder.encodeMessagePack(transaction.toMessagePack());
final signedBytes = await connector.signTransaction(
    txBytes,
    params: {
      'message': 'Optional description message',
    },
);

Wallets

Initiate connection

// Create a connector
final connector = WalletConnect(
    uri: 'wc:8a5e5bdc-a0e4-47...TJRNmhWJmoxdFo6UDk2WlhaOyQ5N0U=',
    clientMeta: PeerMeta(
      name: 'WalletConnect',
      description: 'WalletConnect Developer App',
      url: 'https://walletconnect.org',
      icons: [
        'https://gblobscdn.gitbook.com/spaces%2F-LJJeCjcLrr53DcT1Ml7%2Favatar.png?alt=media'
      ],
    ),
);

// Subscribe to events
connector.on('connect', (session) => print(session));
connector.on('session_request', (payload) => print(payload));
connector.on('disconnect', (session) => print(session));

Manage connection

// Approve session
await connector.approveSession(chainId: 4160, accounts: ['0x4292...931B3']);

// Reject session
await connector.rejectSession(message: 'Optional error message');

// Update session
await connector.updateSession(SessionStatus(chainId: 4000, accounts: ['0x4292...931B3']));

Kill session

await connector.killSession();

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing & Pull Requests

Feel free to send pull requests.

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

Comments
  • How to interact with Smart Contracts.

    How to interact with Smart Contracts.

    This is an amazing plugin which will let the mobile dApps connect to the Decentralised Wallets ( MetaMask , Trust Wallet). Thanks for such an amazing plugin.

    Can we add a feature to interact with smart contracts straight from the mobile dApp ?

    opened by dAppDev03 11
  • Fixes for wallets

    Fixes for wallets

    @RootSoft - there are some issue I've discovered while trying to implement wallet side of WalletConnect:

    • PeerId and PeerMeta correctly returned in approveSession (otherwise dApp will ignore the response)
    • PeerId is added to subscriptions when the session approved
    • PeerId is added to subscriptions when connector is created with existing session (session restoration)
    opened by 3ph 9
  • Feature/ethereum support

    Feature/ethereum support

    @RootSoft I've added a new provider with basic Ethereum methods. I had to reorganise the code a bit as the abstract provider doesn't fit Ethereum methods. This seems to be similar to what other implementations do. Feel free to change that or suggest a different approach.

    I would also update the README once we confirm the final implementation.

    opened by 3ph 6
  • ✨ Auto-Heal Socket Close

    ✨ Auto-Heal Socket Close

    Problem Statement

    Socket gets closed silently by normal events (i.e. app to background). See #8 for more description.

    Fix

    Listen to onError and onDone events and re-open the connection when those events are fired.

    opened by ghunkins 6
  • sign function does not return the correct signature

    sign function does not return the correct signature

    I'm using flutter as my frontend, and using walletconnect-dart-sdk to connect to the metamask mobile app. The idea is to have the user sign a message, and send it to the backend to verify it. The issue is that the signature does not match what is expected compared to everywhere else I have tested it. Here is the code, input, output, and expected values: const messageToSign = "test"; final bytes = utf8.encode(messageToSign); final messageHash = sha256.convert(bytes);

    final signature = await provider.sign(message: '0x$messageHash', address: accountAddress);
    

    accountAddress: 0x7176bd09199068e21be4137d1630fb8712633445 output signature: 0x72e4affbb8555eec0a26e1e1ca55dad89825980f38e374c0faf5572850c6373121f60c8c5d094beebba26c5e3b9c47f9b58ef6f094f2454fed4019baeb730b751c

    Meanwhile, everywhere else I test (like with this verified signature) says that for the message test with the address 0x717... this is the correct signature: 0x78464efcef0520455a04bebd120d6f26cc6bcdd35a1bfe670eaa9d5d3161cab6390acc382ac7d76aa0579ccf568113c900be1ed77d417f235a8b3b8807fc31f71c

    Is this an issue in the package or something else? Also, is there any other ways to sign a message from flutter?

    opened by ericmartihaynes 5
  • How to get the QR code?

    How to get the QR code?

    I tried a minimal example below, but that does not work by itself. Is there an example to show the QR code? Or does one have to create the QR code widget oneself?

    Future<void> main() async {
    
        // Create a connector
        final connector = WalletConnect(
          bridge: 'https://bridge.walletconnect.org',
          clientMeta: PeerMeta(
            name: 'WalletConnect',
            description: 'WalletConnect Developer App',
            url: 'https://walletconnect.org',
            icons: [
              'https://gblobscdn.gitbook.com/spaces%2F-LJJeCjcLrr53DcT1Ml7%2Favatar.png?alt=media'
            ],
          ),
        );
    
        // Set a default walletconnect provider
        connector.setDefaultProvider(AlgorandWCProvider(connector));
    
        // Check if connection is already established
        final session = await connector.createSession(
          chainId: 4160,
          onDisplayUri: (uri) => print(uri),
        );
    }
    
    opened by 2i2i 5
  • Not able to connect Trust wallet

    Not able to connect Trust wallet

    Hello,

    I want to connect to Trust wallet, But unfortunately it doesn't connect with it.

    I have run the Mobile example app of this demo and tried to scan the QR code from the Trust Wallet, but it gives a prompt msg of "Connecting! please wait" , Nothing happens after that.

    opened by VivekMakwana24 4
  • Metamask - Accounts List Length Always 1

    Metamask - Accounts List Length Always 1

    Trying to get a list of accounts when connecting to Metamask. The list always returns the current account that is selected in Metamask, however not all of the accounts. Is this just a Metamask thing or am I missing something? We're implementing a sign-on feature using wallet connect where we would like them to select the account they want to use as their sign on, and on subsequent sign-on's, allow them to see their 'last sign on address'.

    opened by u382514 4
  • Unable to connect wallet in android release mode

    Unable to connect wallet in android release mode

    I tried to connect MetaMask wallet in debug mode and is working fine. But when we create release build it stops working. It still able to open MetaMask, but after unlock the MetaMask account it won't prompt the dialog for connect wallet.

    opened by McDreamy 4
  • eth_sign requires 32 byte message hash

    eth_sign requires 32 byte message hash

    error: JSON-RPC error -32000: eth_sign requires 32 byte message hash

    
      @override
      Future<String> sign(String message, String address) async {
        // TODO: implement sign
        final result = await connector.sendCustomRequest(
          method: 'eth_sign',
          params: [address, message],
        );
    
        return result;
      }
    
    
    opened by AllLuckly 4
  • Session exist error prompt on Android

    Session exist error prompt on Android

    Hi, need some help on solving this issue:

    It only occurs on Android, when connecting i'm getting session exist error even if the app are restarted both the dApp and metamask app.

    IMG_6779

    opened by marqueeeeeee 3
  • Does this package support Binance Smart Chain

    Does this package support Binance Smart Chain

    Hello Please my smart contract was built on BNB chain and i need to allow users login from the mobile app using their wallet. How do i add support for that

    opened by devDonald 2
  • Is there any example for connecting metamask in web that i can refer?

    Is there any example for connecting metamask in web that i can refer?

    I am currently trying to implement wallet connect in my flutter app which can be accessed thro mobile as well as web(Browser). Plugin works fine with mobie devices. but if i try the app in chrome launchUrlString takes to the blank page.I have already installed MM extension as well.

    this is what i got in the URI wc:ae3f3cd6-bf76-4ec6-8409-dadc1b767932@1?bridge=https%3A%2F%2Fs.bridge.walletconnect.org&key=d53c02608fdca278e53321cccdf2f24f73028c81f5459c8d7c9c93724c8e19af

    opened by ajayamal 0
  • [fix] killSession not working, #84

    [fix] killSession not working, #84

    fix #84

    The problem is caused by the use of unawaited, I think it is because the killSession request will not have any response and the author wants to run killSession and then use _handleSessionDisconnect to reset the local state immediately. Unfortunately, the actual situation is that the local state is reset before the killSession request is sent out, so a valid killSession request cannot be sent successfully.

    Future killSession({String? sessionError}) async {
       ...
       unawaited(_sendRequest(request));
       await _handleSessionDisconnect(errorMessage: message, forceClose: true);
       ..
    }
    

    To reduce the impact on other places, I just add a delay to ensure that the killSession request can be sent out before the _handleSessionDisconnect reset local state.

    unawaited(_sendRequest(request));
    // Avoid starting `_handleSessionDisconnect` before completing `_sendRequest`, which will cause the dapp to not be disconnected from the wallet, https://github.com/RootSoft/walletconnect-dart-sdk/issues/84
    await Future.delayed(const Duration(milliseconds: 100));
    await _handleSessionDisconnect(errorMessage: message, forceClose: true);
    

    Hope to approve this PR, please let me know if there are any problems 🙏🏻 Thanks so much

    opened by WingCH 2
  • [iOS][Android]Cannot disconnect wallet after use `killSession`

    [iOS][Android]Cannot disconnect wallet after use `killSession`

    versions: walletconnect_dart: ^0.0.11

    I just want to get the wallet address, so I use killSession after createSession returns the result, but I still see a connection in the wallet app.

    i have tried this MR https://github.com/RootSoft/walletconnect-dart-sdk/pull/75 , but not work.

    Reproduce step

    1. run sample code
    2. click Get Addresses button
    3. choose trust wallet (you can choose other wallet, i believe have same behavior)
    4. the wallet app will show authorize popup, click connect
    5. wallet app will back to sample app automatically and return some information including waller address
    6. After received the waller address, killSession will be executed
    7. back to wallet app manually
    8. find WalletConnect page, check connecting list

    Expected result: not find sample app, since already killSession

    Actual result: sample app in connecting list

    Video

    https://user-images.githubusercontent.com/19588517/200003359-750c0ba4-be1f-455b-86ec-3789330b6910.mp4

    Sample code

    class HomePage extends StatefulWidget {
      const HomePage({Key? key}) : super(key: key);
    
      @override
      State<HomePage> createState() => _HomePageState();
    }
    
    class _HomePageState extends State<HomePage> {
      final WalletConnect connector = WalletConnect(
        bridge: 'https://bridge.walletconnect.org',
        clientMeta: const PeerMeta(
          name: 'My App',
          // if description is null, trust wallet (iOS 7.20 (691)) will not show the connection request
          description: 'An app for converting pictures to NFT',
          url: 'https://walletconnect.org',
          icons: ['https://files.gitbook.com/v0/b/gitbook-legacy-files/o/spaces%2F-LJJeCjcLrr53DcT1Ml7%2Favatar.png?alt=media'],
        ),
      );
    
      void getAddresses() async {
        try {
          var session = await connector.createSession(
            onDisplayUri: (uri) async {
              await launchUrlString(
                uri.toString(),
                mode: LaunchMode.externalApplication,
              );
            },
          );
    
          print('address: ${session.accounts}');
    
          // kill session
          await connector.killSession();
        } catch (e) {}
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: Center(
            child: TextButton(
              onPressed: getAddresses,
              child: const Text('Get Addresses'),
            ),
          ),
        );
      }
    }
    
    

    flutter doctor

    [✓] Flutter (Channel stable, 3.3.7, on macOS 13.0 22A380 darwin-arm, locale zh-Hant-HK)
    [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    [✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
    [✓] Chrome - develop for the web
    [✓] Android Studio (version 2021.3)
    [✓] VS Code (version 1.72.2)
    [✓] Connected device (4 available)
    [✓] HTTP Host Availability
    
    
    opened by WingCH 10
Owner
Tomas Verhelst
Non-Fungible Developer
Tomas Verhelst
Pneumonia and COVID-19 detection Mobile App from Chest X-rays using CNN based deep learning classifiers.

image_classification A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you sta

null 1 Dec 7, 2021
A Deep Learning Based Attendance System is a mobile application that aims to make it easier for lecturers to check the attendance status of students which are attending the course.

Attendance System / Flutter App A Deep Learning Based Attendance System is a mobile application that aims to make it easier for lecturers to check the

Merthan Kavak 11 Oct 24, 2022
Postgres-conector - A library for connecting to and querying PostgreSQL databases in Dart.

TODO: Put a short description of the package here that helps potential users know whether this package might be useful for them. Features TODO: List w

null 2 Nov 14, 2021
Automates CP 2077's "Breach Protocol" hacking minigame

Cyberpwned Cyberpunk 2077 Hacking Minigame Resolver - Play Store: https://play.google.com/store/apps/details?id=com.nicolassiplis.cyberpwned Requireme

Nicolás Siplis 141 Dec 22, 2022
A multi-plateform (Flutter) application for reading your emails, with your favorite devices, using the JMAP protocol!

A multi-plateform (Flutter) application for reading your emails, with your favorite devices, using the JMAP protocol!

LINAGORA 119 Jan 2, 2023
Routinger is a task scheduler app that is made to make you a better person at no extra cost. The code is open-source. Dart language and Flutter framework are used extensively.

Routinger This is a simple app that will allow you to schedule your tasks, create a simple to-do, and also make recurring tasks. The app ends you noti

Routinger 16 Dec 17, 2022
Open source portion code of viewers

Welcome to Shopping App Clone ?? In this project we are going to create the E-commerce Shopping App using Flutter, NodeJs, ExpressJs along with GetX s

Balram Rathore 32 Dec 19, 2022
Naj - An open-source code generation and file management system written in Dart

Naj An open-source code generation and file management system written in Dart Ov

Najibullah Khoda Rahim 1 Feb 14, 2022
Timy - open source mobile app for groups to communicate and organize themselves. Built with flutter.

Timy app An amazing open-source group messaging app build with flutter. ✨ Main Features Multiple groups (similar to Teams in Slack). Multiple open or

null 1.9k Dec 25, 2022
freeCodeCamp's open-source mobile app

freeCodeCamp.org's open-source mobile app freeCodeCamp.org is a friendly community where you can learn to code for free. Our full-stack web developmen

freeCodeCamp.org 248 Jan 9, 2023
Sharik is an open-source, cross-platform solution for sharing files via Wi-Fi or Mobile Hotspot

Share files across devices with Sharik! It works with Wi-Fi connection or Tethering (Wi-Fi Hotspot). No internet connection needed. Contributing Feel

Mark Motliuk 844 Jan 1, 2023
Drishti is an open-source cross-platform mobile application project at Incubate Nepal that incorporates Machine Learning and Artificial Intelligence

Drishti is an open-source cross-platform mobile application project at Incubate Nepal that incorporates Machine Learning and Artificial Intelligence to help visually impaired people recognize different currency bills and perform daily cash transactions more effectively. We plan to expand Drishti to other applications like Short Text and Document Reading in the future.

Drishti Nepal 23 Oct 8, 2022
Flutter Music Player - First Open Source Flutter based material design music player with audio plugin to play local music files.

Flutter Music Player First Open Source Flutter based Beautiful Material Design Music Player(Online Radio will be added soon.) Demo App Play Store BETA

Pawan Kumar 1.5k Jan 8, 2023
Simple yet powerful, open-source SpaceX launch tracker.

SpaceX GO! Simple yet powerful, open-source SpaceX launch tracker About the project The purpose of this project is to develop the ultimate SpaceX expe

Jesús Rodríguez 782 Dec 24, 2022
An open source encrypted peer-to-peer system. Own data, own privacy.

An open source encrypted peer-to-peer system. Own data, own privacy.

Cymple Tech 456 Jan 3, 2023
Nakama is an open-source server designed to power modern games and apps

Nakama is an open-source server designed to power modern games and apps. Features include user accounts, chat, social, matchmaker, realtime multiplayer, and much more.

Allan Nava 85 Dec 30, 2022
Upper is a open source back-end framework based on the Dart language.

What is Upper? Upper is a open source back-end framework based on the Dart language. With it, it is possible to automatically generate a gRPC API for

Andriws Luna 40 Sep 5, 2022
Easy to use open source Hub 🕸️ to control your smart devices from one app.

CyBear Jinni Hub Welcome! This repository is in charge of controlling smart devices and is part of the CyBear Jinni Smart Home system. The software is

CyBear Jinni 26 Nov 23, 2022
Easy to use open source Hub 🕸️ to control your smart devices from one app.

CyBear Jinni Hub Welcome! This repository is in charge of controlling smart devices and is part of the CyBear Jinni Smart Home system. The software is

CyBear Jinni 13 Jul 22, 2021