Domain Steem with JavaScript: Lesson #2 - Exploring the Steem API: Steem JS

in #steemjs-s22w28 days ago (edited)


Add a subheading.jpg
Image taken from Pixabay

Hello everybody.

This is my participation post for SLC Week 2, Domain Steem with JavaScript created by @alejos7ven!

Before starting on the homework tasks, I had to install NodeJS, as I had Visual Studio Code on my PC already.

You can download it from the official website, either by running commands in PowerShell or get a prebuilt installer for your machine. You can choose Windows, Linux, macOS or AIX and the specific architecture. I went for Windows x64.


image.png
Node.JS download page

The installation is pretty straight forward, just follow the steps. After the install is done, we can check the version via CMD, with the node command.


image.png
Node.JS version check

To run Node.js scripts like STEEM JS using Visual Studio Code. After the whole installation process, I created a new folder, in which I opened a CMD terminal and ran the command to install the STEEM JS Library: npm install steem --save. With all this done, I could start working on the tasks.

Now, without further ado, let's get started.

Task 1: Use Steem JS to execute at least 3 methods from Steem API

Method 1: getTrendingTags


The getTrendingTags can be used to retrieve information about the trending tags such as: name, number of comments, number of top posts, total payouts. In the code, you can set how many tags you want find, in my case it's 5:

getTrendingTags.png

The result is a JSON that contains the 5 trending tags and the specific data for them:


image.png

Method 2: getBlogEntries


The second method, getBlogEntries is used to extract information about a specific number of posts from a users blog starting from a particular point. Can be useful when you want to see data about older posts.

In my case, I am using this method to find information about blog entries from 4 to 7, as 7 is the starting point and it will go backwards 4 positions:


image.png
The code used


image.png
The result

Method 3: lookupAccountNames


For the third method, I chose lookupAccountNames which allows me to see detailed information about a list of Steem accounts. You can also check if certain account names exists.

I declared a variable where I specified 2 account names I would like to find information about. For demonstrating how this works, I used my own account and one that does not exists.


accountnames.png

And this is the JSON it returned. As you can see, for my account the API can find information but for the not existing one it returns null:


image.png

Task 2: Calculate the effective SP (vesting_shares+received_vesting_shares-delegated_vesting_shares-vesting_withdraw_rate) for all Steemcurator accounts (sc01-08)

Before we can calculate the SP, we need to find the necessary variables. As a small test, I ran the getAccounts method with my name and extracted the variables. This is the code + the result for my account:


image.png

Now, let's do this for all of the steemcurator's accounts. We also need to use the getDynamicGlobalProperties method so we can get mvests. This is how the final version of the code looks like:


image.png

And this is the result, with 4 digits:


image.png

Task 3: 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

My choice of 5 values:

  • current_sbd_supply This property represents the total amount of SBD currently in circulation. When running the code, we see that the supply is: 13924765.512 SBD
    -virtual_supply is the sum of the all STEEM supply + all SBD supply, if SBD is converted to STEEM at the current median price. At the moment, it would be: 532986348.526 STEEM
  • current_witness is used to find the account name of the current witness. In this case its: dhaka.witness
  • head_block_number: it's value represents the number of the last block that was added in the blockchain. A new block is generated every few seconds
  • sbd_interest_rate: represents the interest rate paid on SBD moved into savings, currently set at 0%



As always, thank you for reading and I'd like to extend an invitation to @r0ssi, @radudangratian and @cmalescov to take part in this.

Sort:  
Loading...

Coin Marketplace

STEEM 0.29
TRX 0.27
JST 0.046
BTC 99539.26
ETH 3650.37
SBD 2.79