sendAsyncTx method

Future<BlockchainResponse> sendAsyncTx(
  1. List<String> params
)

Implementation

Future<BlockchainResponse> sendAsyncTx(List<String> params) async {
  final res = await networkClient.postHTTP('', {
    "jsonrpc": "2.0",
    "id": "dontcare",
    "method": "broadcast_tx_async",
    "params": params
  });
  if (res.data['error'] != null) {
    return BlockchainResponse(
      data: res.data['error'],
      status: BlockchainResponses.error,
    );
  }

  String? transactionHash = res.data['result']['transaction']['hash'];
  String response = res.data['result']['status']['SuccessValue'] != null
      ? NearFormatter.decodeResultOfTransactionResponse(
          res.data['result']['status']['SuccessValue'].toString())
      : "no data in response";
  final String? functionCallError = res.data['result']['status']['Failure']
      ['ActionError']['kind']['FunctionCallError']['ExecutionError'];

  if (res.isSuccess && functionCallError == null) {
    return BlockchainResponse(
      data: {
        "txHash": transactionHash,
        "response": response,
      },
      status: BlockchainResponses.success,
    );
  } else {
    return BlockchainResponse(
      data: {
        "txHash": transactionHash,
        "error": functionCallError,
      },
      status: BlockchainResponses.error,
    );
  }
}