【解決方法】トランザクション送信エラーが発生しました: typeerror: フラッターのブロックチェーン アプリで未定義 (「プロバイダー」の読み取り) のプロパティを読み取ることができません


フラッター
  1  import 'package:flutter_web3/flutter_web3.dart';
  2  import 'package:web3dart/web3dart.dart' as web;
  3  import 'package:web3dart/credentials.dart';
  4  
  5  String currentAddress = '';
  6  bool get isEnabled = ethereum != null;
  7  bool get isConnected =isEnabled && currentAddress.isNotEmpty;
  8  
  9  Future<bool> sendTransaction({required EthereumAddress to}) async {
 10      if (isEnabled) {
 11          final accs = await ethereum!.requestAccount();
 12          if (accs.isNotEmpty)
 13              currentAddress = accs.first; //assign current address to first address
 14          if (currentAddress != '') {
 15              print(currentAddress);
 16          }
 17      }
 18      if (!isConnected) {
 19          return false;
 20      }
 21      try {
 22          final eth = Ethereum.ethereum;
 23          final transaction = web.Transaction(
 24              from: EthereumAddress.fromHex(currentAddress),
 25              to: to,
 26              value: web.EtherAmount.inWei(BigInt.parse("8000")),
 27          );
 28          if (ethereum != null) {
 29              print("Etherem is not null");
 30          }
 31  
 32          final web3provider = Web3Provider(ethereum!);
 33          final signer = provider?.getSigner();
 34          final tx = await signer?.sendTransaction(transaction as TransactionRequest);
 35  
 36          if (tx != null) {
 37              print(tx.hashCode);
 38              return true;
 39          }
 40  
 41          print("Transaction is not performed");
 42          return false;
 43      } catch (e) {
 44          print("Errror sending transaction : $e");
 45          return false;
 46      }
 47  }

私が試したこと:

このコードをクロム(メタマスク拡張機能)で実行すると、アカウントに接続するためにメタマスクがポップアップ表示されますが、その後、TypeErrorが表示されます:未定義のプロパティを読み取ることができません(「プロバイダー」を読み取ります)、エラーが発生していると思います、最終的なweb3provider = Web3Provider(ethereum! ); しかし、その理由と解決方法がわかりません。

解決策 1

「未定義のプロパティを読み取れません」というメッセージは、存在しないオブジェクト、または他の言語では null のオブジェクトを使用しようとした場合に表示される JavaScript のメッセージです。

投稿したコードのどこにも「プロバイダー」プロパティまたはメソッドが呼び出されていることがわかりません。つまり、使用しようとしているライブラリによってエラーがスローされた可能性があります。 それを手伝ってくれるのは、ライブラリを作成した人だけです。

コメント

タイトルとURLをコピーしました