Git Product home page Git Product logo

orange-wallet / wallet-connect-dart Goto Github PK

View Code? Open in Web Editor NEW
116.0 6.0 77.0 146 KB

Wallet Connect client in Dart.

Home Page: https://pub.dev/packages/wallet_connect

License: BSD 3-Clause "New" or "Revised" License

Kotlin 0.14% Swift 0.41% Objective-C 0.04% Dart 64.38% HTML 3.79% CMake 8.42% C++ 20.69% C 0.75% Ruby 1.38%
flutter dart dapp-protocol walletconnect library ethereum hacktoberfest

wallet-connect-dart's Introduction

Wallet Connect Logo

Wallet Connect

Wallet Connect client in dart highly inspired from wallet-connect-kotlin by Trust Wallet.

Usage

    import 'package:wallet_connect/wallet_connect.dart';
  1. Create instance of Wallet connect client and define callbacks.
    final wcClient = WCClient(
      onConnect: () {
        // Respond to connect callback
      },
      onDisconnect: (code, reason) {
        // Respond to disconnect callback
      },
      onFailure: (error) {
        // Respond to connection failure callback
      },
      onSessionRequest: (id, peerMeta) {
        // Respond to connection request callback
      },
      onEthSign: (id, message) {
        // Respond to personal_sign or eth_sign or eth_signTypedData request callback
      },
      onEthSendTransaction: (id, tx) {
        // Respond to eth_sendTransaction request callback
      },
      onEthSignTransaction: (id, tx) {
        // Respond to eth_signTransaction request callback
      },
    );
  1. Create WCSession object from wc: uri.
    final session = WCSession.from(wcUri);
  1. Create WCPeerMeta object containing metadata for your app.
    final peerMeta = WCPeerMeta(
        name: 'Example Wallet',
        url: 'https://example.wallet',
        description: 'Example Wallet',
        icons: [],
    );
  1. Connect to a new session.
    wcClient.connectNewSession(session: session, peerMeta: peerMeta);
  1. Or connect to a saved session (from step 8).
    wcClient.connectFromSessionStore(sessionStore);
  1. Approve a session connection request.
    wcClient.approveSession(
        accounts: [], // account addresses
        chainId: 1, // chain id
    );
  1. Or reject a session connection request.
    wcClient.rejectSession();
  1. Get active session from sessionStore getter to save for later use.
    final sessionStore = wcClient.sessionStore;
  1. Approve a sign transaction request by signing the transaction and sending the signed hex data.
    wcClient.approveRequest<String>(
        id: id,
        result: signedDataAsHex,
    );
  1. Approve a send transaction request by sending the transaction hash generated from sending the transaction.
    wcClient.approveRequest<String>(
        id: id,
        result: transactionHash,
    );
  1. Approve a sign request by sending the signed data hex generated.
    wcClient.approveRequest<String>(
        id: id,
        result: signedDataAsHex,
    );
  1. Or reject any of the requests above by specifying request id.
    wcClient.rejectRequest(id: id);
  1. Disconnect from a connected session locally.
    wcClient.disconnect();
  1. Permanently close a connected session.
    wcClient.killSession();

wallet-connect-dart's People

Contributors

ayushbherwani1998 avatar erginersoy avatar lioragnin avatar naiba avatar thelazyindian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

wallet-connect-dart's Issues

personal sign error

step 1:
open url: https://opensea.io/asset/create
connect walletconnect with qr code

step2:
sign message

then error:
Authentication error: Relay request for authLoginMutation failed by the following reasons: 1. [401] Not authorized. login(address: $address, identity: $identity, message: $ ^^^
WX20211004-210911@2x

Support for dApp clients: add send requests capability

Great package!

Could we put on the roadmap, the ability to initiate the RPC requests in order to support DApp integrations more easily?

From what I understand, this package provides the receiver/wallet side of the protocol, but I am looking to use Flutter to ask a wallet connect capable wallet to personal_sign, eth_signTypedData etc. (e.g. https://docs.walletconnect.com/1.0/json-rpc-api-methods/ethereum#eth_signtypeddata https://docs.walletconnect.com/1.0/quick-start/dapps/client#sign-typed-data-eth_signtypeddata)

The package already initiates rpc requests with updateSession() in lib/wc_client.dart, so adding "sendRequestXXX" should be straightforward. I think... ;-)

Even supporting a single 'Send Custom Request' method would help, as we could author our own support with effort.

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.

have a Wallet Connect v2 upgrade schedule?

Wallet Connect v1 is will end of support. ( 2022. 12. 16 )
Do you have any plan support Wallet Connect v2?
[(https://medium.com/walletconnect/walletconnect-v1-0-sunset-notice-and-migration-schedule-8af9d3720d2e)

wc.approveRequest cannot be received by dapp.

I'm working on a wallet app with wallet connect.
When I got a request by onEthSendTransaction, I just did these things below:

  1. Get the info from wallet connect.
  2. Sign the transaction.
  3. Send transaction by web3 and get the txHash.
  4. wc.approveRequest(id: id, result: txHash). And the id is get from 1.

I can check the transaction on explorer. But the dapp web is still waiting for me to confirm the transaction.

Is there anyone can help me?
Thanks!

[WCClient] Expose _isConnected through getter

Description

When connecting multiple sessions through WC and caching the connected sessions list, it's important for us to know whether the WCClient is already connected or not, so we can restore the session or initiate a connection.

How can i call walletconnect with web3dart in flutter

i have a smart contract with multiple functions that allow user to pay bills in crypto currencies .i just want to known how can i call smart contract functions through web3dart without private key.I already connect wallet with walletconnect but how can i use them instead of private key.Is there any option in walletconnect to call smart contract function?.

wrong network

from pancakeswap.finance: "You are connected to the wrong network

Not Working for Android

I tried with sample app in android but it is not working.
Not connect or not showing up other things like application selection.
Is there any way to use it in android app.

ERC20 tokens

Hello. I see only eth example, but how can I check and handle erc20 token transaction? Cause if this is a token transfer that it should be other handling in web3. Can you show an example with tokens?

Update Session never updates.

Future<void> updateSession({ List<String>? accounts, int? chainId, bool approved = true, }) async { final param = WCSessionUpdate( approved: approved, chainId: _chainId ?? chainId, accounts: accounts, ); final request = JsonRpcRequest( id: DateTime.now().millisecondsSinceEpoch, method: WCMethod.SESSION_UPDATE, params: [param.toJson()], ); return _encryptAndSend(jsonEncode(request.toJson())); }

In this block chainId is never updated. It always uses current _chainId .

to Update Session we need to call approveSession method first then call updateSession method

How to track dapp?

The wallet can be connected to more than one dapps. How do we know which dapp triggered the function?? For example, if we take onEthSign...

image

Unable to disconnect

When I use wcClient.disconnect() to disconnect, but Dapp shows that I am still connected.

How to kill just one session?

I had connecting to two Dapps, now i want to disconnect from only one Dapp.
I try to use killsession, and two Dapps' sessions were been killed.
Please teach me how to do, thank you.

Android Support/Docs

I've been trying the example and connecting to Metamask app on my phone, I am unsure if this is web-only, or does it support android too, because it doesn't show a list of apps when I open it on my android phone, do I need to make some additional configurations ? I was unsure as there is not any documentation around it, within the codebase too. It'd be great if I can get some help figuring this out.

Update pub.dev

hello, first of all, thank you very much for the package you developed. The wallet connect plugin on pub.dev is out of date. The updateSession function is not working because it was last updated 11 months ago and there are no chainID changes.

Sign message error

step1:
open the opensea.io, and connect walletconnect

step2:
open profile -> collected, and open the own collect.

step3:
click the sell button, to sell my collect.

step4:
set the price, click "Complete listing" button, then click "unlock" button

step5:
click "sign" button in walletconnect.

then error:
There was an error with your transaction. Please try again.

WX20211005-115439@2x

Select Metamask from wallet list and nothing happens

By clicking "Connect to WalletConnect", a popup shows up, when I select Metamask from the wallet list, nothing happens. Below error shows up. Does it suppose to open the installed Metamask App?

flutter: URL https://metamask.app.link/wc?uri=wc%3Afa84513a-96c6-4852-b07e-15a09eba0195%401%3Fbridge%3Dhttps%253A%252F%252Fx.bridge.walletconnect.org%26key%3D2c2f2074740415feb3bf76d8c7bfd0d30baa108c431999673028e7b99be96f46

InAppWebView - dealloc

flutter: URL https://metamask.app.link/wc?uri=wc%3Afa84513a-96c6-4852-b07e-15a09eba0195%401%3Fbridge%3Dhttps%253A%252F%252Fx.bridge.walletconnect.org%26key%3D2c2f2074740415feb3bf76d8c7bfd0d30baa108c431999673028e7b99be96f46

flutter: URL itms-apps://apps.apple.com/app/id1438144202

[ProcessSwapping] 0x114001210 - [pageProxyID=6, webPageID=48, PID=83828, navigationID=5] ProvisionalPageProxy::didFailProvisionalLoadForFrame: frameID=3

[Process] 0x10105ac18 - [pageProxyID=6, webPageID=7, PID=83751] WebPageProxy::didFailProvisionalLoadForFrame: frameID=3, domain=, code=0, isMainFrame=1

[assertion] Error acquiring assertion: <Error Domain=RBSServiceErrorDomain Code=1 "target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit" UserInfo={NSLocalizedFailureReason=target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit}>

[ProcessSuspension] 0x1130045a0 - ProcessAssertion: Failed to acquire RBS assertion 'ConnectionTerminationWatchdog' for process with PID=83828, error: Error Domain=RBSServiceErrorDomain Code=1 "target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit" UserInfo={NSLocalizedFailureReason=target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit}

[assertion] Error acquiring assertion: <Error Domain=RBSAssertionErrorDomain Code=2 "Specified target process does not exist" UserInfo={NSLocalizedFailureReason=Specified target process does not exist}>

[ProcessSuspension] 0x113004600 - ProcessAssertion: Failed to acquire RBS assertion 'WebProcess Background Assertion' for process with PID=83828, error: Error Domain=RBSAssertionErrorDomain Code=2 "Specified target process does not exist" UserInfo={NSLocalizedFailureReason=Specified target process does not exist}

Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service

Issue about the disconnect without reason

Sometimes the program will be exited without reason
the close code is 1005
For the definition of code, refer to the definition document of Web Socket
https://www.rfc-editor.org/rfc/rfc6455#section-7.4

(Actually it's always 1005 when the dapp call loginout, the sdk will not notify program,and direct call disconnect then throw a code of 1005,for example, on opensea.io),see the following code.
close
listen
It is noteworthy that
_ webSocket._ webSocket._ closeCode
_ webSocket._ webSocket._ closeReason
There are values in.But obviously these are internal properties I can't access. In addition, I added the Reason and Close parameters on my own initiative.

So in the onDisconnect event, I can't determine whether it is an unexpected end or the user's active end
(If it is an accidental termination, I can reconnect and continue to communicate with DAPP, but if it is the user's active termination, there is no connection significance.)

The difference between the two is that when DAPP is disconnected, according to the official document of WalletConnect, a SessionUpdate method must be sent.
So I added this onSessionUpdate event and called it so that the program can determine whether to reconnect or disconnect
add function call
add function

Sending a transaction requires manually switch to Metamask to confirm

Environment

I'm trying to develop a mobile app in Flutter which should interact with a very simple contract.
The contract contains a basic string which can be read or write.

My environment is the following:

  • Ganache running on localhost, with the contract deployed at a know address.
  • A physical Android device with adb-reverse to reach the Ganache network.
  • On the Android I've Metamask app installed with the Ganache network set and one of the Ganache account.

I'm using the following dependencies:

  web3dart: ^2.3.0
  walletconnect_dart: ^0.0.11
  url_launcher: ^6.1.5

I use the Web3Dart code generator to generate the class to interact with my contract.

Expected behaviour

The app has a login button, which redirect the user to Metamask for the login, and it initialise the session.
After that it displays a screen with a text containing the value of the contract variable, a textField and a button.
Tapping on the button should execute a transaction that updates the value on the contract with the textField content.

Problem

After looking around on Github for examples I was able to assemble the code and make it work.
The EthClient, the Connector and the Contract are initialised correctly.
At login button tap the user is switched to Metamask and a popup ask to connect to the mobile app.
After that the user can interact with the TextField and submit the new value.

I copied the WalletConnectEthereumCredentials from the example folder and here's my version:

class WalletConnectEthereumCredentials extends CustomTransactionSender {
  WalletConnectEthereumCredentials(
      {required this.provider});

  final EthereumWalletConnectProvider provider;

  @override
  Future<EthereumAddress> extractAddress() => Future(
      () => EthereumAddress.fromHex(provider.connector.session.accounts.first));

  @override
  Future<String> sendTransaction(Transaction transaction) async {
    final from = await this.extractAddress();
    final hash = await provider.sendTransaction(
      from: from.hex,
      to: transaction.to?.hex,
      data: transaction.data,
      gas: transaction.maxGas,
      gasPrice: transaction.gasPrice?.getInWei,
      value: transaction.value?.getInWei,
      nonce: transaction.nonce,
    );

    return hash;
  }

  @override
  Future<MsgSignature> signToSignature(Uint8List payload,
      {int? chainId, bool isEIP1559 = false}) {
    // TODO: implement signToSignature
    throw UnimplementedError();
  }
}

When the user tap on the button, a transaction is sent.
Now if the user want to proceed he has to open manually Metamask and confirm the transaction through a popoup.

Is there a way to avoid having to move in Metamask and confirm every simple transaction every time, then switch back in the app?

I was able to automatically open Metamask every time a transaction is sent, with this code inside the sendTransaction:

 launchUrlString(metamaskUri, mode: LaunchMode.externalApplication);

But still a confirmation for every transaction is needed.

Thanks

Example without an InAppWebView or show code from example.openwallet.org?

I wanted to use this plugin to try and sign in to my Metamask wallet on iOS or Android completely natively, but your example uses an InAppWebView that completely hides what happens when we click the "Connect to WalletConnect" button. As a Wallet Connect newbie I'm completely lost. Is it a requirement to go through a web page that does most of the work like that, and if so, can you share how you implemented the website on example.openwallet.org? And if it's possible to do everything natively, could you show an example of how to do that, with clearer indication as to what the values for each parameter should be? Right now the documentation is not very helpful.

How to generate wc: uri

As per the docs, after creating instance of WCClient, we need to create a session:

final wcUri = '...';
final session = WCSession.from(wcUri);

I am new to blockchain and crypto wallets.
Can some one please help me understand, how can I create the wcUri?
Also, does the WCClient automatically stores the session and we don't need to re-authenticate on every app launch?

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.