Domain Steem with JavaScript: Lesson #2 - Exploring the Steem API: Steem JS
Image taken from Pixabay
So I've had NodeJS already installed from my previous attempts to create my own Chrome extension, I just needed to check in CMD if it's still there, with a simple node
command you can get the current version installed.
Now all that I still needed was something the replace the ugly white notepad so I went with Visual Studio Code, this one also has some packages that could really help in the future.
Without further ado, let's check the tasks given by @alejos7ven. If you'd also like to join you can find all the details here Domain Steem with JavaScript: Lesson #2 - Exploring the Steem API: Steem JS
- Use Steem JS to execute at least 3 methods from Steem API [2 PTS]
Method 1
First Method to be executed is the Get Active Votes one, in the documentation it looks like this:
It is used to get the active votes on a specific post, it requires the author name and a perm link as parameters and it returns a JSON with details about the votes casted on the set link.
I declared two variables one for the author and one for the perm link, set the author to my name and gave it my last post's perm link and ran the code. The output JSON looks like this.
As you can see you have different stats from the users that voted on the selected post (voter's name, weight, the time stamp, voting percent etc.)
Method 2
The second Method, Get Content, this one includes the details provided by the above method too.
With the Get Content method we can access the whole content of an author's post (community, title, body, images used in the post etc.) and we also have included the JSON from the previous method mentioned the active votes.
Here's the code used, I've used the same author and perm link as before:
You can see all the details in the JSON below:
Method 3
And now for the last method let's use the Estimate Account Value one and see how much an account is estimated at. To do that we are going to use the getAccounts
method with the estimateAccountValue
.
I moved this inside my Visual Studio, replaced the username with my username and ran it.
The output result is the account value calculated in USD, and it looks like this:
- Calculate the effective SP (vesting_shares+received_vesting_shares-delegated_vesting_shares-vesting_withdraw_rate) for all Steemcurator accounts (sc01-08) [5 PTS]
We need to start by finding the vesting_shares
received_vesting_shares
delegated_vesting_shares
and vesting_withdraw_rate
, to use in the formula provided by @alejos7ven.
I started by running the getAccounts
method with my name as parameter to see what details we can get from this JSON. And it looks like this:
And in this JSON we can find the needed data for our task, I tried showing them for my account only, as a test and it worked.
Now let's change this code and organize it a little, I will move every value to a variable and I have to remove the word VESTS to be able to perform the formula.
This is the final form before moving to the steemcurator's accounts.
And the final form of the code:
And the result of the code:
- Study the get_dynamic_global_properties method and explain at least 5 values we can get here. Use this site: https://developers.steem.io/tutorials-recipes/understanding-dynamic-global-properties [3 PTS]
- The 5 values:
vote_power_reserve_rate
Vote Power Reserve Rate represents the number of votes regenerated over 24 hours, in our case we can have 10 votes at 100% voting weight and it's being regenerated at 1 vote every 2.4hrs (2 hours and 24mins). Currently set to 10, voting less then this number and you are wasting votes, vote more and you get reduced voting.head_block_number
Head Block Number represents the latest block produced by the witnesses, running the method every few seconds will show you that a new block is being generated every few seconds.current_supply
Current supply represents the number of all STEEM that currently exists, this number is not affected/doesn't take into consideration the SBD.sbd_interest_rate
SBD Interest rate is the interest rate paid on the SBD you move into savings, currently set to 0, at one point I think this was 10% APR or so can't really remember.virutal_supply
Virtual supply compared to the current supply is the combination of all STEEM supply + all SBD supply if SBD were converted to steem at a median current price.
That was it with this post, thank you @alejos7ven can't wait for the next week's course. This was my first time working with steem js, I'd like to invest more time into learning it and who knows even create something at one point.
In the end I'd like to invite @r0ssi, @mojociocio and @titans.