Development
...
Querying Data from Blockchain
Paginated Transactions
1 min
the docid\ yynxycqblmbwflxzom4c6 limits the amount of returned transaction to at maximum 500 this is to avoid unnecessary resource usage if you want to fetch more (or also less) transactions you can paginate the requests async function listtransactions({account, page, pagesize}) { // all api calls are asynchronous // the recommended pattern is using async/await // this makes exception handling easy using try/catch try { // we check if incoming account is either a signum address, or numeric id // eventually, we convert to numeric id const accountid = address create(account) getnumericid() const firstindex = page pagesize // now, we call the getaccounttransactions method, // we use the indexing feature to fetch pages of transactions const {transactions} = await ledger account getaccounttransactions( { firstindex, lastindex firstindex + pagesize, includeindirect true, // multi out payments are included accountid, } ); // now we map the fields we want to print as a table to console then // note for sake of simplicity we do not filter out the multi payments const mappedtransactions = transactions map(t => { const hasreceived = t sender !== accountid return { date chaintime fromchaintimestamp(t timestamp) getdate(), account hasreceived ? t senderrs t recipientrs || 'self', value `${hasreceived ? '+' ' '} ${amount fromplanck(t amountnqt) tostring()}`, // convert from planck value to signa fee amount fromplanck(t feenqt) tostring() } }); console table(mappedtransactions, \['date', 'value', 'fee', 'account']) } catch (e) { // if the api returns an exception, // the return error object is of type httperror console error(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 () => { await listtransactions({ account 'ts qaja qw5y swvp 4rvp4', page 2, pagesize 50 }); })();