-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (32 loc) · 1.48 KB
/
index.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
const { default: axios } = require("axios");
const converter = require("json-2-csv");
var fs = require("fs");
async function getTransactionsByAccount(accountHash) {
let url = `https://event-store-api-clarity-mainnet.make.services/accounts/${accountHash}/transfers?page=1&limit=100`;
const response = await axios.get(url);
const pageCount = response.data.pageCount;
const itemCount = response.data.itemCount;
let transactions = [];
console.log("Total of ", pageCount, " pages found");
console.log("Found ", itemCount, " transactions");
// console.log('data = ', response.data.data)
transactions = [...transactions, ...response.data.data];
for (let index = 2; index <= pageCount; index++) {
console.log("Getting transactions in page ", index);
let url = `https://event-store-api-clarity-mainnet.make.services/accounts/${accountHash}/transfers?page=${index}&limit=100`;
const response = await axios.get(url);
// const type =
// response.data.data.fromAccount === accountHash ? "Sent" : "Received";
transactions = [...transactions, ...response.data.data];
}
return transactions;
}
async function main() {
const accountHash = process.argv[2];
console.log("Extracting transactions of ", accountHash);
const transactions = await getTransactionsByAccount(accountHash);
console.log("transactions length = ", transactions.length);
const csv = await converter.json2csvAsync(transactions);
fs.writeFileSync(`${accountHash}_transactions.csv`, csv);
}
main();