Flutter - 使用钱包连接连接Trust Wallet

4

我正在尝试创建一个可以通过WalletConnect连接到移动钱包(例如:Metamask、TrustWalet等)的移动应用程序,但我找不到相关信息。

是否已经有方法可以在Flutter应用程序中实现WalletConnect?

2个回答

1
您需要使用 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


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

更多信息请查看:链接


3
抱歉,我认为该实现是在构建一个钱包应用程序,而不是为想要连接到钱包的dapp服务。 - Viet Hoang

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接