sendTransaction method

Future sendTransaction(
  1. Map<String, dynamic> transaction
)

Asks connected wallet to sign and send the transaction.

Implementation

Future<dynamic> sendTransaction(Map<String, dynamic> transaction) async {
  if (!connected) {
    throw WalletNotConnectedError(null);
  }

  Map<String, dynamic> options = {
    'required_messages_number': transaction['messages']?.length ?? 0
  };
  _checkSendTransactionSupport(wallet!.device!.features, options);

  Map<String, dynamic> request = {
    'valid_until': transaction['validUntil'],
    'from': transaction['from'] ?? wallet!.account!.address,
    'network': transaction['network'] ?? wallet!.account!.chain.value,
    'messages': transaction['messages'] ?? []
  };

  Map<String, dynamic> response = await provider!
      .sendRequest(SendTransactionParser().convertToRpcRequest(request));

  if (SendTransactionParser().isError(response)) {
    return SendTransactionParser().parseAndThrowError(response);
  }

  return SendTransactionParser().convertFromRpcResponse(response);
}