Ok, so I spent some time banging my head against the wall trying to figure out the steem-js library and since then I have found myself helping out others by answering questions wherever I can in different chats. A lot of the same questions seem to come up though so I am going to do my best to capture them and other little things I have learned while building the steem.press website. First of all let me say that I have been working in Javascript on and off since 2000 and I think the most exciting thing I have ever encountered is async await. It makes some of the asynchronous coding so much easier and more readable. If you want this code to work you probably will need to be using a transpiler. Actually that makes me think of something important to mention. If you are new to javascript do yourself a favor and don't start by diving right into the steem-js code. The odds of you figuring it out without having a good understanding of what it does and how are slim to none in my opinion. It is great that you want to build something cool but trying it without a thorough understanding of javascript is like deciding you are going to write the great American novel but only having the vocabulary of a 3rd grader. It will only end in frustration for you. Ok with that out of the way I am going to keep this first one short and sweet but I think it has a few very valuable points to be learned. Below is my code I use for getting all of a users followers. First I make a call to get the follower and following counts. `const followCount = await Steem.api.getFollowCountAsync(username);` Now even though the method is called getFollow count it actually returns an object that contains both counts. It does not however contain a muted count(this will be important in a later step). `followCount.follower_count and followCount.following_count` ok, now that I have my count I can get all the follower names. You can only get a maximum of one thousand followers at a time so you have to loop through the list. I've added comments to the lines below to describe what I am doing. If you are an experienced JS developer most of this is going to seem very obvious but there will be one nugget of gold in there. ```javascript async getFollowers(username, count) { let retVal1 = []; // here I am just creating an empty array that I will return let startFollower = ''; //In the example code on github startfollower is 0 but that really doesn't work accept for the first pass for(let i = 0; i < count; i+=1000) { let temp = await Steem.api.getFollowersAsync(username, startFollower, 'blog', 1000); // startFollower is a name not a number Array.prototype.push.apply(retVal1, temp); // push values onto my return array startFollower = retVal1[retVal1.length-1].follower; // get the name of the startFollower for the next call } return retVal1; } ``` when calling getFollowersAsync or getFollowers you can only obtain a maximum of 1000 at a time so it is important that before you end the current iteration of your look you set start follower to last follower in the list you just got back. When I first wrote this I had startFollower set to i since in the documentation it has a 0 I assumed this was the number of the follower you wanted to start with. The only reason passing in 0 gives you the expected result is because there is no user named 0 and so it just starts at the beginning. If on the next pass you were to pass in 1000 then you would get the same list of people again because there is no user named @1000 Hopefully this and future entries in my dev series will help in some way. If there is something specific about the api you would like to see covered please be sure to leave a comment. All the code I post works inside of my app but sometimes I will have to make slight adjustments since I am trying to contain the code as much as possible. One last note, after years of object oriented programming I have seen the light on functional programming. I try whenever possible to stick to pure functional programming so that given the same input I get the same output. That said, I again may make some alterations at times to my actual code before posting it here. Hopefully everything is perfect as posted but I am human so typos and other mistakes can and will occur.
post_id | 9,554,370 |
---|---|
author | voorash |
permlink | new-steem-dev-series-1 |
category | steemit |
json_metadata | "{"app": "steemit/0.1", "format": "markdown", "tags": ["steemit", "software", "dev", "steemdev", "steempress"]}" |
created | 2017-08-08 10:38:24 |
last_update | 2017-08-08 16:42:18 |
depth | 0 |
children | 7 |
net_rshares | 16,214,813,776,914 |
last_payout | 2017-08-15 10:38:24 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 46.167 SBD |
curator_payout_value | 14.403 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 4,322 |
author_reputation | 2,386,589,786,858 |
root_title | "New steem dev series - #1" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
transisto | 0 | 2,496,292,983,551 | 23% | ||
newsflash | 0 | 13,547,063,328,476 | 100% | ||
mkt | 0 | 18,764,100,729 | 100% | ||
davidk | 0 | 2,242,451,272 | 100% | ||
jfollas | 0 | 19,507,878,334 | 100% | ||
bubke | 0 | 125,532,507,288 | 100% | ||
alexandruionescu | 0 | 92,501,969 | 5.75% | ||
voorash | 0 | 5,318,025,295 | 100% | ||
gustavoaca1997 | 0 | 0 | 100% |
Thanks, could you maybe do a little post e.g. starting blockchain dev for dummies. I am developper in exotic unknown languages, would love to look at blockchain, have no clue where to start, cheers...
post_id | 9,555,765 |
---|---|
author | bubke |
permlink | re-voorash-new-steem-dev-series-1-20170808t105835200z |
category | steemit |
json_metadata | "{"app": "steemit/0.1", "tags": ["steemit"]}" |
created | 2017-08-08 10:58:39 |
last_update | 2017-08-08 10:58:39 |
depth | 1 |
children | 3 |
net_rshares | 5,264,307,868 |
last_payout | 2017-08-15 10:58:39 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 201 |
author_reputation | 8,776,742,025,360 |
root_title | "New steem dev series - #1" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
voorash | 0 | 5,264,307,868 | 100% |
Will follow you in the hope you do something like that..
post_id | 9,555,808 |
---|---|
author | bubke |
permlink | re-bubke-re-voorash-new-steem-dev-series-1-20170808t105911519z |
category | steemit |
json_metadata | "{"app": "steemit/0.1", "tags": ["steemit"]}" |
created | 2017-08-08 10:59:15 |
last_update | 2017-08-08 10:59:15 |
depth | 2 |
children | 0 |
net_rshares | 0 |
last_payout | 2017-08-15 10:59:15 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 56 |
author_reputation | 8,776,742,025,360 |
root_title | "New steem dev series - #1" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
Ok, I have to ask. What exotic unknown languages do you develop in. Also, are you talking about creating a blockchain or do you just mean dev for interacting with a blockchain. I am assuming you meant interacting with.
post_id | 9,584,486 |
---|---|
author | voorash |
permlink | re-bubke-re-voorash-new-steem-dev-series-1-20170808t164543382z |
category | steemit |
json_metadata | "{"app": "steemit/0.1", "tags": ["steemit"]}" |
created | 2017-08-08 16:45:42 |
last_update | 2017-08-08 16:45:42 |
depth | 2 |
children | 1 |
net_rshares | 0 |
last_payout | 2017-08-15 16:45:42 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 219 |
author_reputation | 2,386,589,786,858 |
root_title | "New steem dev series - #1" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
Yes, interacting, i am programming in Omnis for 25 years, multi platform, multi database. Gooood money of which i have almost enough and i feel like supporting the blockchain revolution. I have univ degree in IT and economics so i am not too stupid, would love to implement socalled triple ledger accounting or implement blockchain in accounting, many applications like loans, assets, etc... Hey, thank you for asking :-)
post_id | 9,586,706 |
---|---|
author | bubke |
permlink | re-voorash-re-bubke-re-voorash-new-steem-dev-series-1-20170808t170859504z |
category | steemit |
json_metadata | "{"app": "steemit/0.1", "tags": ["steemit"]}" |
created | 2017-08-08 17:09:03 |
last_update | 2017-08-08 17:09:03 |
depth | 3 |
children | 0 |
net_rshares | 0 |
last_payout | 2017-08-15 17:09:03 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 425 |
author_reputation | 8,776,742,025,360 |
root_title | "New steem dev series - #1" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
@voorash thanks for the explanation. I have not digged into the steem-js lib yet but I will probably soon enough. This series could get me started. Suggestion for your code examples: you could use the verbatim formatting by surrounding your code with ***\`\`\`***. It will output like this: ``` followCount.follower_count and followCount.following_count ```
post_id | 9,557,221 |
---|---|
author | oroger |
permlink | re-voorash-new-steem-dev-series-1-20170808t111923158z |
category | steemit |
json_metadata | "{"app": "steemit/0.1", "users": ["voorash"], "tags": ["steemit"]}" |
created | 2017-08-08 11:19:24 |
last_update | 2017-08-08 11:19:24 |
depth | 1 |
children | 1 |
net_rshares | 5,156,873,013 |
last_payout | 2017-08-15 11:19:24 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 360 |
author_reputation | 1,383,920,399,736 |
root_title | "New steem dev series - #1" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
voorash | 0 | 5,156,873,013 | 100% |
Thanks, I figured there was a way to do that but something inspired me to write the post at 5:30 in the morning before I went to bed and was suffering from good enough syndrome. I'll edit this one :)
post_id | 9,583,518 |
---|---|
author | voorash |
permlink | re-oroger-re-voorash-new-steem-dev-series-1-20170808t163509879z |
category | steemit |
json_metadata | "{"app": "steemit/0.1", "tags": ["steemit"]}" |
created | 2017-08-08 16:35:09 |
last_update | 2017-08-08 16:35:09 |
depth | 2 |
children | 0 |
net_rshares | 0 |
last_payout | 2017-08-15 16:35:09 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 199 |
author_reputation | 2,386,589,786,858 |
root_title | "New steem dev series - #1" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
Same made the same experience. It is all about code-reuse, and in many cases, you can achieve it easier with FP. > One last note, after years of object-oriented programming I have seen the light on functional programming. I try whenever possible to stick to pure functional programming so that given the same input I get the same output. Thanks for the article. I hope you have written some more …
post_id | 25,772,783 |
---|---|
author | cutemachine |
permlink | re-voorash-new-steem-dev-series-1-20180115t064857391z |
category | steemit |
json_metadata | "{"app": "steemit/0.1", "tags": ["steemit"]}" |
created | 2018-01-15 06:48:57 |
last_update | 2018-01-15 06:48:57 |
depth | 1 |
children | 0 |
net_rshares | 0 |
last_payout | 2018-01-22 06:48:57 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 400 |
author_reputation | 13,216,337,213,922 |
root_title | "New steem dev series - #1" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |