Skip to content

Instantly share code, notes, and snippets.

@kolya-t
Last active January 29, 2019 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kolya-t/986cc8375917cfcd74980b3de96462e8 to your computer and use it in GitHub Desktop.
Save kolya-t/986cc8375917cfcd74980b3de96462e8 to your computer and use it in GitHub Desktop.
tron-accounts
{
"main": "tron-accounts.js",
"scripts": {
"start": "node tron-accounts.js"
},
"dependencies": {
"axios": "^0.18.0",
"progress": "^2.0.3"
}
}
const http = require('axios');
const fs = require('fs');
const ProgressBar = require('progress');
const FILENAME = 'tron-accounts.csv';
async function getAccounts(start = 0, limit = 100, attempts = 3) {
const url = `https://apilist.tronscan.org/api/account/list?limit=${limit}&start=${start}`;
try {
const response = await http.get(url);
return response.data;
} catch (e) {
if (attempts <= 1) {
throw e;
}
return getAccounts({start, limit, attempts: attempts - 1});
}
}
(async () => {
const limit = 1000;
const bar = new ProgressBar(' [:bar]:percent :current/:total :etas', {
complete: '=',
incomplete: ' ',
width: 30,
total: 1000000000
});
fs.writeFileSync(FILENAME, '');
for (let i = 0; ; i = i + limit) {
const accounts = await getAccounts(i, limit);
let string = '';
accounts.data.forEach(account => {
string += `${account.address},${account.balance}\n`;
});
fs.appendFileSync(FILENAME, string);
bar.tick(accounts.data.length);
bar.total = accounts.total;
if (accounts.data.length === 0) {
break;
}
}
console.info();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment