Flutter - 使用 wallet connect 连接信任钱包

我正在尝试创建一个可以通过 WalletConnect 连接到移动钱包(例如:Metamask、TrustWalet...)的移动应用程序,但我找不到任何东西。

有什么方法可以在 Flutter 应用上实现 walletconnect 吗?

stack overflow Flutter - Connect trust wallet using wallet connect
原文答案

答案:

作者头像
dependencies:
  wallet_connect: ^1.0.2

  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
      },
    );

更多检查: Link

作者头像

你需要 walletconnect_darturl_launcher

import 'package:url_launcher/url_launcher_string.dart';
import 'package:walletconnect_dart/walletconnect_dart.dart';

// 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(
        onDisplayUri: (uri) async {
        _uri = uri;
        await launchUrlString(uri, mode: LaunchMode.externalApplication);
      }
    );
}

欲了解更多信息,请访问 walletconnect_dart