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 {
    log(
      'callSCFunction: requestHttp.body=${json.encode(jsonRPCRequest)}',
      logsActivation: logsActivation,
    );

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

    log(
      'callSCFunction: responseHttp.body=${responseHttp.body}',
      logsActivation: logsActivation,
    );

    if (responseHttp.statusCode == 200) {
      if (resultMap) {
        completer.complete(
          getJsonRPCResult(responseHttp.body),
        );
      } else {
        completer.complete(
          getJsonRPCResultString(responseHttp.body),
        );
      }
    }
  } catch (e) {
    log(
      'callSCFunction: error=$e',
      logsActivation: logsActivation,
    );
    rethrow;
  }
  return completer.future;
}