merigo-labs / solana-wallet-adapter

MIT License
6 stars 2 forks source link

Transaction Timing Out #3

Open WilfredAlmeida opened 1 year ago

WilfredAlmeida commented 1 year ago

I'm trying to transfer SOL from the user's Phantom wallet to my address, I'm getting Future Timeout Exception after sending the transaction. Following is the code

            final adapter = SolanaWalletAdapter(
              const AppIdentity(),
              cluster: Cluster.devnet,
            );

            var blockHash = await web3.Connection(Cluster.devnet).getLatestBlockhash();

            AuthorizeResult result = await adapter.authorize();

            final transaction = web3.Transaction();
            transaction.add(
              SystemProgram.transfer(
                fromPublicKey: web3.PublicKey.fromBase64(result.accounts[0].address),
                toPublicKey: web3.PublicKey.fromString('3zH9A4Yo65EWTdYppQNWBK3mXExbaNNQ2P3PpWVkLspA'),
                lamports: web3.solToLamports(10),
              ),
            );

            final mTransaction = transaction.copyWith(
              feePayer: web3.PublicKey.fromBase64(result.accounts[0].address),
              recentBlockhash: blockHash.blockhash,
            );

            var res = await adapter.signAndSendTransactions(
              transactions: [
                mTransaction.toJsonClean().toString(),
              ],
            );

            print(res.signatures[0]);

Following is the exception I'm getting

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: TimeoutException: Connection timed out.

Nothing else is printed in the console.

WilfredAlmeida commented 1 year ago

Update: I installed Solflare wallet and tried the transaction. It took me to the 'Swipe to Confirm' screen and said something went wrong.

Following is the error printed in console of Android Studio

E/flutter (18737): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method callAsyncJavaScript on channel com.pichillilorenzo/flutter_inappwebview_1142227165188133165229102196201722511362810077)
E/flutter (18737): #0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:294)
E/flutter (18737): <asynchronous suspension>
E/flutter (18737): #1      InAppWebViewController.callAsyncJavaScript (package:flutter_inappwebview/src/in_app_webview/in_app_webview_controller.dart:2300)
E/flutter (18737): <asynchronous suspension>
E/flutter (18737): #2      StakingService.getStakeAccounts (package:solflare/blockchain/solana/sdk/action/staking/staking_service.dart:22)
E/flutter (18737): <asynchronous suspension>
E/flutter (18737): #3      StakingFragmentCubit._getStakingAccounts (package:solflare/staking/fragment/bloc/staking_fragment_cubit.dart:62)
E/flutter (18737): <asynchronous suspension>
E/flutter (18737): #4      StakingFragmentCubit.onReload (package:solflare/staking/fragment/bloc/staking_fragment_cubit.dart:56)
E/flutter (18737): <asynchronous suspension>
E/flutter (18737): 
E/flutter (18737): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method callAsyncJavaScript on channel com.pichillilorenzo/flutter_inappwebview_1142227165188133165229102196201722511362810077)
E/flutter (18737): #0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:294)
E/flutter (18737): <asynchronous suspension>
E/flutter (18737): #1      InAppWebViewController.callAsyncJavaScript (package:flutter_inappwebview/src/in_app_webview/in_app_webview_controller.dart:2300)
E/flutter (18737): <asynchronous suspension>
E/flutter (18737): #2      SolanaSimulation.getSimulatedBalanceChanges (package:solflare/blockchain/solana/sdk/action/simulation/solana_simulation.dart:22)
E/flutter (18737): <asynchronous suspension>
E/flutter (18737): #3      Future.wait.<anonymous closure> (dart:async/future.dart:522)
E/flutter (18737): <asynchronous suspension>
E/flutter (18737): #4      ConfirmTransactionCubit._loadSimulationInitially (package:solflare/transaction/bloc/confirm_transaction/confirm_transaction_cubit.dart:150)
E/flutter (18737): <asynchronous suspension>
E/flutter (18737): 
E/flutter (18737): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method callAsyncJavaScript on channel com.pichillilorenzo/flutter_inappwebview_1142227165188133165229102196201722511362810077)
E/flutter (18737): #0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:294)
E/flutter (18737): <asynchronous suspension>
E/flutter (18737): #1      InAppWebViewController.callAsyncJavaScript (package:flutter_inappwebview/src/in_app_webview/in_app_webview_controller.dart:2300)
E/flutter (18737): <asynchronous suspension>
E/flutter (18737): #2      NameService.getTwitterHandleForPublicKey (package:solflare/blockchain/solana/sdk/action/name_service/name_service.dart:28)
E/flutter (18737): <asynchronous suspension>
E/flutter (18737): #3      PortfolioCubit._getTwitterHandle (package:solflare/portfolio/fragment/bloc/portfolio_cubit.dart:227)
E/flutter (18737): <asynchronous suspension>
E/flutter (18737): #4      Future.wait.<anonymous closure> (dart:async/future.dart:522)
E/flutter (18737): <asynchronous suspension>
E/flutter (18737): #5      PortfolioCubit._getPortfolioData (package:solflare/portfolio/fragment/bloc/portfolio_cubit.dart:143)
E/flutter (18737): <asynchronous suspension>
E/flutter (18737): #6      PortfolioCubit.setTokenAccountCubit.<anonymous closure> (package:solflare/portfolio/fragment/bloc/portfolio_cubit.dart:130)
E/flutter (18737): <asynchronous suspension>
E/flutter (18737): 
E/flutter (18737): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method callAsyncJavaScript on channel com.pichillilorenzo/flutter_inappwebview_2131146238212174218802118119917149167197207214)
E/flutter (18737): #0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:294)
E/flutter (18737): <asynchronous suspension>
E/flutter (18737): #1      InAppWebViewController.callAsyncJavaScript (package:flutter_inappwebview/src/in_app_webview/in_app_webview_controller.dart:2300)
E/flutter (18737): <asynchronous suspension>
E/flutter (18737): #2      ActivityService.initialize (package:solflare/blockchain/solana/sdk/action/activity/activity_service.dart:32)
E/flutter (18737): <asynchronous suspension>
E/flutter (18737): #3      TokenAccountCubit._onRefresh (package:solflare/shared/bloc/token_account/token_account_cubit.dart:95)
E/flutter (18737): <asynchronous suspension>
merigo-labs commented 1 year ago

Hi @WilfredAlmeida,

The TimeoutException can occur if your device is running in low power mode, the websocket can get disconnected.

The transaction error looks like an encoding issue. The adapter now provides the encodeTransaction helper method for this.

Please try the following:

  1. Update to the latest versions of the packages (these contain breaking changes)

    solana_web3: ^0.1.1
    solana_wallet_adapter: ^0.1.1
  2. Try and run this code (adjusted for the library updates)

    
    final adapter = SolanaWalletAdapter(
    const AppIdentity(),
    cluster: Cluster.devnet,
    );

var blockHash = await web3.Connection(Cluster.devnet).getLatestBlockhash();

AuthorizeResult result = await adapter.authorize();

final payer = web3.Pubkey.fromBase64(result.accounts[0].address); final transaction = web3.Transaction.v0( payer: payer, recentBlockhash: blockHash.blockhash, instructions: [ SystemProgram.transfer( fromPubkey: payer, toPubkey: web3.Pubkey.fromBase58('3zH9A4Yo65EWTdYppQNWBK3mXExbaNNQ2P3PpWVkLspA'), lamports: web3.solToLamports(0.01), ), ], );

var res = await adapter.signAndSendTransactions( [ adapter.encodeTransaction(transaction) ], );



Let me know if you need anything else!

Thanks
Merigo
WilfredAlmeida commented 1 year ago

Hii @merigo-labs, thanks for the response.

The code you gave works and the transaction goes through and the funds are transferred.

However, the error in the console still exists. I tried it on 2 physical devices, both without any power saving enabled and battery above 60%.

Let me know if I can help with solving/providing any additional info for the same.

Regards, Wilfred Almeida wilfredalmeida.com

merigo-labs commented 1 year ago

Hi @WilfredAlmeida,

I've also seen console errors when using Solflare that I don't see in other wallets. I might need to run this by the Solflare team to see what they think.

Thanks Merigo

WilfredAlmeida commented 1 year ago

Cool. Currently the transaction details show all unknown. I'll keep this issue open until I figure that and close it.

If you want otherwise then all cool from my side. The main problem highlighted in the issue is now solved.

Thanks for your help, I've been stuck on this for the past 2 weeks.

Regards, Wilfred Almeida wilfredalmeida.com

merigo-labs commented 1 year ago

I think we should keep it open for now.

I've seen the unknown error when I don't provide AppIdentity information to the wallet. Here's a quick guide on how you set it up on Android. You need to host an assets links file at your domain.