How to iterate over account history items

in #javascript7 years ago (edited)

Using steem.js, it is easy to iterate over all the history items of an account. However, if you have not done this before, it may be a little tricky, because there is not enough documentation on the web (or maybe I didn’t find it).

Anyway, steem.api.getAccountHistory returns a promise that resolves to a batch of history items. Each item has an ID number (that starts with 1 for the first item in the history). The batch returned is sorted ascendingly, and contains limit + 1 items, starting at from. If you want to start at the most recent item, you can give from a value of -1. Otherwise, from must be larger than or equal to limit.

Here is an example code for getting history items:

    for (let from = -1, limit = 100, going = true; !!from && going; ) {
        let items = await steem.api.getAccountHistory(username, from, Math.min(limit, from));
        from = items[0][0] - 1;
        items.reverse();
        loop:
        for (let item of items) {
            if (someTest(item)) {
                going = false;
                break loop;
            }
            // do something with item
        }
    }

The loop ends if we reach the first item (hence the use of !!from) or if someTest(item) returns true.

Sort:  

It's totally a new thing for me. Thanks for sharing this important information.

Loading...

I didn't know about it. But i am interested to know about it.

your are really good at programming, i also like progaramming , l like c language

nice ♥

Good writing.Its help us .

Sir! Is your account hacked? 3 consecutive posts other than idioms? Never seen it before~!

I am going to post more content like this. I am currently doing a programming project and I will be posting some of the tips that I think may be useful.

I do have an interest in computer programming but it takes too much time to get used to it. But after all its worth to give time to learn it.

1117.jpg

Helpful post...

You are doing a lot of good work. It looks very good to me because of your work. You are teaching us Persian language very much.

Wonderful and informative technology. Excellent post.

Really great post

very interesting good post @ghasemkiani

Wow...Amazing post..I appreciate technology..I like javascript.thanks for share...

Nice post. i like this technology thanks for sharing. @ghasemkiani

Thanks for this programming tutorial.Javascript is very useful for all browser,and huge app.
Carry on you activity

Its very good lesson for us and this post very useful.
Thabks sir @ghasemkiani for sharing information post.

Stay blessed

Helpful post thanks for information @ghasemkiani

Thanks for your educative post

good post


Thanks for this post,,very nice technology my dear friend @ghasemkiani

nice post dear @ghasemkiani. i miss you all time your post

Its very interesting and informative blog. Its very nice steeming
All the best


Now I began to think hard about posting idioms.

I hope your help for idiom posting tricks in order to follow your footsteps.
Thanks so much :)hi my dear friend @ghasemkiani. my post is not desirable as posting idioms you my friend @ghasemkiani.

I need to know more about it, this is era of technology and we need to be informed. Please I need more tutorial from you thanks

nice post friends with beautiful article.

its pretty helpful. btw jquery could be more shorter... anyway great work

Helpful for us.

Thats a great sir..I appreciate ...

i like this technology thanks for sharing i within for you next post best of luck..

Very useful tutorial on javascript.

That a great post. its a helpfull for us.

wow , you create a new kind of post.

nice....helpfull post...thanks


Your posts are very good
I like it ...Hallo my friend @ghamsekiani

If you do not mind upvote my post too: https://www.steemit.com/sports/@mahyul/join-madrid-neymar-ready-to-be-paid-cheap

Steem Bot Tracker websitevote for @yabapmatt for witness!You got a 0.78% upvote from @postpromoter courtesy of @ghasemkiani! Want to promote your posts too? Check out the for more info. If you would like to support development of @postpromoter and the bot tracker please