Get Account Transactions
Getting and manipulating transactions from the Stacks blockchain.
Getting Account Transactions
Node.js
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) {
let counter = 0;
let total = 0;
let limit = 50;
let url = "";
let txResults = [];
// 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
do {
url = `${stxApi}/extended/v1/address/${address}/transactions?limit=${limit}&offset=${counter}`;
const response = await fetch(url);
if (response.status === 200) {
// success
const responseJson = await response.json();
// get total number of tx
if (total === 0) {
total = responseJson.total;
console.log(`Total Txs: ${total}`);
}
// add all transactions to main array
responseJson.results.map((tx) => {
txResults.push(tx);
counter++;
});
// output counter
console.log(`Processed ${counter} of ${total}`);
} else {
// error
throw new Error(
`getAccountTxs response err: ${response.status} ${response.statusText}`
);
}
// pause for 1sec, avoid rate limiting
await timer(1000);
} while (counter < total);
// view the output
//console.log(JSON.stringify(txResults));
return txResults;
}
getAccountTxs("SP3CK642B6119EVC6CT550PW5EZZ1AJW661ZMQTYD");
Filtering Transactions
MIA Mining
NYC Mining Claims
MIA Stacking
NYC Stacking Claims
Last updated
Was this helpful?