RE: How to iterate over account history items

You are viewing a single comment's thread from:

How to iterate over account history items

in javascript •  7 years ago 

I've been doing it a little differently. Here's a helper function that I wrote in order to parse the account history of any given account, but only output the "transfer" transactions. The general idea is the same, but here it is so folks can see a concrete example of a test. In this case parsing out only transactions:

let steem = require('steem');

steem.api.setOptions({ url: 'https://api.steemit.com' });


function getAllAccountTransactions( username ){

    steem.api.getAccountHistory(username, -1, 0, (err, result) => {
        limit = result[0][0];

            while(limit >= 0){
                steem.api.getAccountHistory(username, limit, 100, (err, result) => {
                    result.map((r) => {
                        r[1].op[0] == 'transfer' ? console.log(r[1]) : '' ;
                    });
                    
                });

                limit -= 101;
            }
    });
} 

process.on('unhandledRejection', (reason, p) => {
});


getAllAccountTransactions('sha256md5');
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

That's a good approach. Thank you for posting a concrete example.

One difference is that I have used .reverse() to maintain a consistent descending order. This is important if you want to stop the search based on finding a particular kind of transaction.