sendTx method

Future<String> sendTx(
  1. String signedTx
)

Implementation

Future<String> sendTx(String signedTx) async {
  final resp = await _layer1ApiPost('/transactions', signedTx);

  if (resp.statusCode != HttpStatus.ok) {
    return Future.error(HttpResponseError(resp.statusCode, resp.body));
  }

  final body = json.decode(resp.body);
  final txResp = SendTransactionResponse.fromJson(body);

  if (txResp.data.invalid.isNotEmpty) {
    return Future.error(HttpResponseError(
      resp.statusCode,
      'Transaction failed: ${json.encode(txResp.errors)}',
    ));
  }

  if (txResp.data.accept.length > 1) {
    return Future.error(HttpResponseError(
      resp.statusCode,
      'sendTx expected 1 accepted tx, got ${txResp.data.accept.length}. Response: ${resp.body}',
    ));
  }
  return txResp.data.accept[0];
}