SteemJs 101 : How to get details about a particular post
What Will I Learn?
- How to see contents of a post using steemJs
Requirements
- Little or no knowledge in Javascript
Difficulty
- Intermediate
Tutorial Contents
In this tutorial series, am going to be explaining methods in the steemJs which will help you be able to code an application based on the steem blockchain.
Today, we are going to be looking at how to get the content of a post, ranging from the title of the post to the active votes where you can then filter the result to get the weight each user voted at and with this you can create an application like esteem where a user can see details about his/her post.
So without further talks, lets dive into the work for the day.
To accomplish the above said, we will be using the getContent() method in the steemJs where the documentation can be found here - https://github.com/steemit/steem-js/tree/master/doc.
Explanation of arguements:
the author argument is a string variable - meaning if you wanted to get informations about a post made me, the author value would be - edetebenezer.
the permlink argument is also a string but not the complete url, but only the one from the /.
And then informations are logged using the console.log(err,result) line.
So lets get the details of my last post - with the title -
A Java program to check if a number is automorphic, display automorphic numbers within a range and generate automorphic numbers using eclipse IDE.
the appropriate code would be -
steem.api.getContent("edetebenezer", "a-java-program-to-check-if-a-number-is-automorphic-display-automorphic-numbers-within-a-range-and-generate-automorphic-numbers", function(err, result) {
console.log(err, result);
});
and on logging it, you will get the following but not limited to -
from the author_reputation value - 3277962980565, you can get the users reputation from another call using the method -
console.log(steem.formatter.reputation(result.author_reputation)); - which becomes = 56.
One other important information one can get also is the active votes of the post which can be gotten from the active_votes array.
which gives the following information - percent, reputation of the voter, rshares, time, voter and weight(to get the actual vote, one must divide the weight by 100).
Therefore one can come up with the following, User "username" upvoted this post at weight - "weight"
This can be achieved this way using a for loop -
for (var i = 0; i < result.active_votes.length; i++) {
console.log("User "+result.active_votes[i].voter+" upvoted this post at weight "+result.active_votes[i].weight/100);
}
More tutorials to come, stay tuned in!
Posted on Utopian.io - Rewarding Open Source Contributors