callViewFunction method

Future<Map> callViewFunction(
  1. String contractId,
  2. String methodName,
  3. String methodArgs
)

Allows you to call a contract method as a view function.

Implementation

Future<Map<dynamic, dynamic>> callViewFunction(
    String contractId, String methodName, String methodArgs) async {
  var body = json.encode({
    "jsonrpc": "2.0",
    "id": "dontcare",
    "method": "query",
    "params": {
      "request_type": "call_function",
      "finality": "final",
      "account_id": contractId,
      "method_name": methodName,
      "args_base64": methodArgs
    }
  });

  Map<String, String> headers = {};
  headers[Constants.contentType] = Constants.applicationJson;

  try {
    http.Response responseData =
        await http.post(Uri.parse(providerURL), headers: headers, body: body);
    Map jsonBody = jsonDecode(responseData.body);
    return jsonBody;
  } catch (exp) {
    return {"EXCEPTION": exp};
  }
}