getTransactions method Null safety
Query the network to find a transaction chain
@param {String} The Address
scalar type represents a cryptographic hash used in the ArchEthic network with an identification byte to specify from which algorithm the hash was generated. The Hash appears in a JSON response as Base16 formatted string. The parsed hash will be converted to a binary and any invalid hash with an invalid algorithm or invalid size will be rejected
@param {int} The page
@param {String} The endpoint
Returns the Content
scalar type represents transaction content. Depending if the content can displayed it will be rendered as plain text otherwise in hexadecimal
Implementation
Future<TransactionsResponse> getTransactions(
String address, int page, String endpoint) async {
final Completer<TransactionsResponse> _completer =
Completer<TransactionsResponse>();
TransactionsResponse? transactionsResponse = TransactionsResponse();
final Map<String, String> requestHeaders = {
'Content-type': 'application/json',
'Accept': 'application/json',
};
final String _body =
'{"query":"query { transactionChain(address: \\"$address\\", page: $page) {address, type, data { ledger { uco { transfers { amount, to } }, nft { transfers { amount, to, nft } } } } } }"}';
print(_body);
try {
final http.Response responseHttp = await http.post(
Uri.parse(endpoint + '/api'),
body: _body,
headers: requestHeaders);
print(responseHttp.body);
if (responseHttp.statusCode == 200) {
transactionsResponse = transactionsResponseFromJson(responseHttp.body);
}
} catch (e) {
print('error: ' + e.toString());
}
_completer.complete(transactionsResponse);
return _completer.future;
}