sendTx method

Future<TransactionStatus> sendTx(
  1. Transaction transaction
)

Send a transaction to the network @param {Object} tx Transaction to send

Implementation

Future<TransactionStatus> sendTx(Transaction transaction) async {
  final completer = Completer<TransactionStatus>();

  var transactionStatus = TransactionStatus();
  log('sendTx: requestHttp.body=${transaction.convertToJSON()}');
  try {
    final responseHttp = await http.post(
      Uri.parse('$endpoint/api/transaction'),
      body: transaction.convertToJSON(),
      headers: kRequestHeaders,
    );
    log('sendTx: responseHttp.body=${responseHttp.body}');
    transactionStatus = transactionStatusFromJson(responseHttp.body);

    completer.complete(transactionStatus);
  } catch (e) {
    log(e.toString());
  }

  return completer.future;
}