-
Notifications
You must be signed in to change notification settings - Fork 3
/
list-transactions.js
49 lines (41 loc) · 1.88 KB
/
list-transactions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// const {isBurstAddress, convertAddressToNumericId, BurstValue} = require("@burstjs/util");
const {Address} = require("@signumjs/core");
const {Amount} = require("@signumjs/util");
const {api, askAccount, handleApiError} = require('./helper');
async function listTransactions(account) {
// we check if incoming account is either a BURST Address, or Numeric Id
// eventually, we convert to Numeric Id
const accountId = Address.create(account).getNumericId()
// All API calls are asynchronous
// The recommended pattern is using async/await
// This makes exception handling easy using try/catch
try {
// Now, we call the getAccountTransactions method,
// but we want only the 100 most recent transactions, including multi-out
const {transactions} = await api.account.getAccountTransactions(
{
firstIndex: 0,
lastIndex: 100,
includeIndirect: true,
accountId,
}
);
// now we map the fields we want to print as a table to console then
const mappedTransactions = transactions.map(t => ({
recipient: t.recipientRS || 'Multiple Recipients', // we assume that undefined recipient field is multiout
value: Amount.fromPlanck(t.amountNQT).toString(), // convert from NQT aka Planck value to Burst
fee: Amount.fromPlanck(t.feeNQT).toString()
}));
console.table(mappedTransactions, ['recipient', 'value', 'fee'])
} catch (e) {
// If the API returns an exception,
// the return error object is of type HttpError
handleApiError(e);
}
}
// // Our entry point has to be async, as our subsequent calls are.
// // This pattern keeps your app running until all async calls are executed
(async () => {
const {account} = await askAccount();
await listTransactions(account);
})();