callViewMethod method
Implementation
Future<BlockchainResponse> callViewMethod({
required String contractId,
required String method,
Map<String, dynamic> args = const {},
}) async {
final res = await networkClient.postHTTP("", {
'jsonrpc': '2.0',
'id': 'dontcare',
'method': 'query',
'params': {
'request_type': 'call_function',
'finality': 'final',
'account_id': contractId,
'method_name': method,
'args_base64': NearFormatter.argstobase64Args(args),
},
});
if (res.isSuccess) {
if (res.data['error'] != null || res.data['result']['error'] != null) {
return BlockchainResponse(
data: res.data['error'] ?? res.data['result']['error'],
status: BlockchainResponses.error,
);
}
final decodedResponse =
NearFormatter.decodeViewCallResponse(List<int>.from(res.data['result']?['result']));
return BlockchainResponse(
data: {"response": decodedResponse},
status: BlockchainResponses.success,
);
} else {
return BlockchainResponse(
data: {
"error": res.data,
},
status: BlockchainResponses.error,
);
}
}