import fetch from "node-fetch";
// returns a Promise that resolves after 'ms' milliseconds
const timer = (ms) => new Promise((res) => setTimeout(res, ms));
// fetches all account transactions for a given address or contract identifier
async function getAccountTxs(address) {
// bonus points if you use your own node!
let stxApi = "https://stacks-node-api.mainnet.stacks.co";
console.log(`checking address: ${address}`);
// obtain all account transactions 50 at a time
url = `${stxApi}/extended/v1/address/${address}/transactions?limit=${limit}&offset=${counter}`;
const response = await fetch(url);
if (response.status === 200) {
const responseJson = await response.json();
// get total number of tx
total = responseJson.total;
console.log(`Total Txs: ${total}`);
// add all transactions to main array
responseJson.results.map((tx) => {
console.log(`Processed ${counter} of ${total}`);
`getAccountTxs response err: ${response.status} ${response.statusText}`
// pause for 1sec, avoid rate limiting
} while (counter < total);
//console.log(JSON.stringify(txResults));
getAccountTxs("SP3CK642B6119EVC6CT550PW5EZZ1AJW661ZMQTYD");