New steem dev series - #1 by voorash

View this thread on steempeak.com
· @voorash · (edited)
$60.57
New steem dev series - #1
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.
👍  , , , , , , , ,
properties (23)
post_id9,554,370
authorvoorash
permlinknew-steem-dev-series-1
categorysteemit
json_metadata"{"app": "steemit/0.1", "format": "markdown", "tags": ["steemit", "software", "dev", "steemdev", "steempress"]}"
created2017-08-08 10:38:24
last_update2017-08-08 16:42:18
depth0
children7
net_rshares16,214,813,776,914
last_payout2017-08-15 10:38:24
cashout_time1969-12-31 23:59:59
total_payout_value46.167 SBD
curator_payout_value14.403 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length4,322
author_reputation2,386,589,786,858
root_title"New steem dev series - #1"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (9)
@bubke ·
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...
👍  
properties (23)
post_id9,555,765
authorbubke
permlinkre-voorash-new-steem-dev-series-1-20170808t105835200z
categorysteemit
json_metadata"{"app": "steemit/0.1", "tags": ["steemit"]}"
created2017-08-08 10:58:39
last_update2017-08-08 10:58:39
depth1
children3
net_rshares5,264,307,868
last_payout2017-08-15 10:58:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length201
author_reputation8,776,742,025,360
root_title"New steem dev series - #1"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (1)
@bubke ·
Will follow you in the hope you do something like that..
properties (22)
post_id9,555,808
authorbubke
permlinkre-bubke-re-voorash-new-steem-dev-series-1-20170808t105911519z
categorysteemit
json_metadata"{"app": "steemit/0.1", "tags": ["steemit"]}"
created2017-08-08 10:59:15
last_update2017-08-08 10:59:15
depth2
children0
net_rshares0
last_payout2017-08-15 10:59:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length56
author_reputation8,776,742,025,360
root_title"New steem dev series - #1"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@voorash ·
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.
properties (22)
post_id9,584,486
authorvoorash
permlinkre-bubke-re-voorash-new-steem-dev-series-1-20170808t164543382z
categorysteemit
json_metadata"{"app": "steemit/0.1", "tags": ["steemit"]}"
created2017-08-08 16:45:42
last_update2017-08-08 16:45:42
depth2
children1
net_rshares0
last_payout2017-08-15 16:45:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length219
author_reputation2,386,589,786,858
root_title"New steem dev series - #1"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@bubke ·
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 :-)
properties (22)
post_id9,586,706
authorbubke
permlinkre-voorash-re-bubke-re-voorash-new-steem-dev-series-1-20170808t170859504z
categorysteemit
json_metadata"{"app": "steemit/0.1", "tags": ["steemit"]}"
created2017-08-08 17:09:03
last_update2017-08-08 17:09:03
depth3
children0
net_rshares0
last_payout2017-08-15 17:09:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length425
author_reputation8,776,742,025,360
root_title"New steem dev series - #1"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@oroger ·
@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
```
👍  
properties (23)
post_id9,557,221
authororoger
permlinkre-voorash-new-steem-dev-series-1-20170808t111923158z
categorysteemit
json_metadata"{"app": "steemit/0.1", "users": ["voorash"], "tags": ["steemit"]}"
created2017-08-08 11:19:24
last_update2017-08-08 11:19:24
depth1
children1
net_rshares5,156,873,013
last_payout2017-08-15 11:19:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length360
author_reputation1,383,920,399,736
root_title"New steem dev series - #1"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (1)
@voorash ·
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 :)
properties (22)
post_id9,583,518
authorvoorash
permlinkre-oroger-re-voorash-new-steem-dev-series-1-20170808t163509879z
categorysteemit
json_metadata"{"app": "steemit/0.1", "tags": ["steemit"]}"
created2017-08-08 16:35:09
last_update2017-08-08 16:35:09
depth2
children0
net_rshares0
last_payout2017-08-15 16:35:09
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length199
author_reputation2,386,589,786,858
root_title"New steem dev series - #1"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@cutemachine ·
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 …
properties (22)
post_id25,772,783
authorcutemachine
permlinkre-voorash-new-steem-dev-series-1-20180115t064857391z
categorysteemit
json_metadata"{"app": "steemit/0.1", "tags": ["steemit"]}"
created2018-01-15 06:48:57
last_update2018-01-15 06:48:57
depth1
children0
net_rshares0
last_payout2018-01-22 06:48:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length400
author_reputation13,216,337,213,922
root_title"New steem dev series - #1"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000