我想连接到任何Solana钱包,如Phantom、Sollet、TrustWallet等,但似乎没有要集成的包。我试过-1.我尝试了Dart JS Interop的幻影,但也不是很好。也许solana钱包适配器从typescript到dart的转变可以带来任何解决方案。任何帮助都是感激不尽的,谢谢!
iibxawm41#
I have a (crude) working piece of code// web/index.html
<script src="../lib/wallet.js" />
// wallet.js
class ClientWallet { constructor() { this.pubKey = ''; } async connect() { const resp = await window.solana.connect(); this.pubKey = resp.publicKey.toString(); } address() { return this.pubKey; } disconnect() { window.solana.disconnect(); } } var walletModule = { ClientWallet: ClientWallet };
// main.dart
import 'package:js/js.dart'; import 'package:js/js_util.dart'; @JS('walletModule.ClientWallet') class ClientWallet { external Future<void> connect(); external void disconnect(); external String get pubKey; } Future<void> connectWallet() async { ClientWallet wallet = ClientWallet(); await promiseToFuture(wallet.connect()); }
And then for connecting simply call connectWallet(). This works for me for the Phantom wallet.EDIT: To accomplish this I went to the docs for connecting a Phantom wallet . I also had to use Dart-JS interop to make it work.
svgewumm2#
目前还没有办法做到这一点,除非存在一个额外的外部包。最好的办法可能是将wallet绑定添加到community Dart包中:https://github.com/cryptoplease/cryptoplease-dart
6rqinv9w3#
你可以用我的包flutter_phantom这是签名和发送事务示例
Future<web3.Transaction> createTransactionTransfer() async { final transaction = web3.Transaction( feePayer: phantom.phantomWalletPublicKey, recentBlockhash: (await connection.getLatestBlockhash()).blockhash); transaction.add( SystemProgram.transfer( fromPublicKey: phantom.phantomWalletPublicKey, toPublicKey: phantom.phantomWalletPublicKey, lamports: web3.solToLamports(1), ), ); return transaction; } void signAndSendTransaction() async { try { web3.Transaction transaction = await createTransactionTransfer(); web3.Buffer transactionSerialize = transaction .serialize(const web3.SerializeConfig(requireAllSignatures: false)); final url = phantom.generateSignAndSendTransactionUri( transaction: transactionSerialize, redirect: "onSignAndSendTransaction"); launchUrl( url, mode: LaunchMode.externalNonBrowserApplication, ); } catch (e) { print(e) } }
如何使用此软件包flutter_phantom-demo完整示例
3条答案
按热度按时间iibxawm41#
I have a (crude) working piece of code
// web/index.html
// wallet.js
// main.dart
And then for connecting simply call connectWallet(). This works for me for the Phantom wallet.
EDIT: To accomplish this I went to the docs for connecting a Phantom wallet . I also had to use Dart-JS interop to make it work.
svgewumm2#
目前还没有办法做到这一点,除非存在一个额外的外部包。最好的办法可能是将wallet绑定添加到community Dart包中:https://github.com/cryptoplease/cryptoplease-dart
6rqinv9w3#
你可以用我的包flutter_phantom
这是签名和发送事务示例
如何使用此软件包flutter_phantom-demo完整示例