callSCFunction method

Future<Object> callSCFunction({
  1. required SCCallFunctionRequest jsonRPCRequest,
  2. bool resultMap = false,
})

Call a smart contract's function @param {SCCallFunctionRequest} RPC Request @param {bool} Format of the response (true=Map, false=String)

Implementation

Future<Object> callSCFunction({
  required SCCallFunctionRequest jsonRPCRequest,
  bool resultMap = false,
}) async {
  final completer = Completer<Object>();
  try {
    _logger.fine(
      'callSCFunction: requestHttp.body=${json.encode(jsonRPCRequest)}',
    );

    final responseHttp = await http.post(
      Uri.parse('$endpoint/api/rpc'),
      body: json.encode(jsonRPCRequest),
      headers: kRequestHeaders,
    );

    _logger.fine('callSCFunction: responseHttp.body=${responseHttp.body}');

    if (responseHttp.statusCode == 200) {
      if (resultMap) {
        completer.complete(
          getJsonRPCResult(responseHttp.body),
        );
      } else {
        completer.complete(
          getJsonRPCResultString(responseHttp.body),
        );
      }
    }
  } catch (e, stack) {
    _logger.severe(
      'callSCFunction failed',
      e,
      stack,
    );
    rethrow;
  }
  return completer.future;
}