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

in #steemjs-s22w27 days ago (edited)

Assalamualaikum my fellows I hope you will be fine by the grace of Allah. Today I am going to participate in the steemit learning challenge season 22 week 2 by @alejos7ven under the umbrella of steemit team. It is about Exploring the Steem API: Steem JS. Let us start exploring this week's teaching course.

Orange and Green Illustration Computer Science Presentation.png

Made with Canva

Use Steem JS to execute at least 3 methods from Steem API

First of all to use the Steem JS we need to have Node.js. Because without node.js we cannot run the node scripts. So I moved to the https://nodejs.org/en to download the latest stable version of the Node.js from its official website.


image.png

The latest stable version of the Node.js is LTS version. The next latest version is not stable yet so I will use LTS version. I have downloaded it.

nodejs.PNG

After downloading it I have installed it to use its functionality and to run the node scripts. It took some time for the installation. You can see the files are being installed. After the complete installation we can use node.js in the IDE.

Capture.PNG

Now to confirm the installation of the node.js I have headed towards the command prompt. For the confirmation we can run the command node to see if we get the response Welcome to Node.js. It also returns the version number of the Node.js. On the other hand if we run the command node -v then it only returns the version number of the Node.js.

So now the node.js is fully installed and now we can use the Steem JS library. But before using this library we need to install this library in our laptop or pc.

Installation of Steem JS

For the installation of the Node.js there is a special command but before this we need to create a directory in which the Steem JS library files will be saved and on the run time the data will be used from them.

So I have created the directory with the name steem-js-project. Now in this directory I will install the Steem JS library. So in the cmd I run this command cd steem-js-project to open this directory.

After opening the directory I run this command npm init -y to create the package.json file. In this file all the data will be installed and loaded such as modules, dev dependencies and packages and all other data which is required to use the Steem JS library and run the node scripts.


image.png

Here you can see that all the data has been loaded and saved in the package.json file. We can use this npm install steem to update the library. This command checks all the packages as well and tells about the risks of the packages associated with them. And now we are ready to move to the next work and to run the methods from the Steem API using this Steem JS library.

1. getAccounts

This getAccounts retrieves information about one or more user accounts on the Steem blockchain. The method accepts an array of account names as an input parameter and returns an array of account objects containing various attributes. Such attributes include balance, reputation, vesting shares, post and voting history, and creation date of an account, among others.


image.png

This method is particularly useful for fetching public details of user profiles and monitoring activities such as the amount of Steem Power (vested STEEM) or their posting statistics. Developers often use this method to display user profiles in applications or analyze account activity.

image.png

Here you can see the output of the method getAccounts we can see that it has returned all the information associated with the account. In the account name section I have added name steemit. This is the data of the account steemit. Similarly if we want to get the details of any other account we need to change the account name and it will return the account details of that account.


2. getRewardFund

The getRewardFund method fetches details about a specific reward pool on the blockchain. The Steem blockchain maintains reward pools (like "post") from which author and curator rewards are distributed. This method is essential for understanding how rewards are allocated during content creation and curation.

image.png

The function accepts the name of the reward fund as an argument, typically "post", and returns information like the current balance of the reward, recent claims, and the median price of STEEM. Such information is useful for developers to understand the dynamics of the reward system and to optimize applications that interact with content rewards.


image.png

Here I have run this method in the terminal where I have input the reward name as post and it has fetched data of the reward for the posts. If we see the result keenly then we can observe that the reward balance for the posts is 910246.238 STEEM. And this data shows that posts reward is divided into two parts where the percent of the curation rewards is 5000 and percent content rewards is 10000. The author reward is convergent linear and the curation reward is convergent square root.


3. getDynamicGlobalProperties

The getDynamicGlobalProperties method returns real-time information regarding the global state of the Steem blockchain. Such properties include the current head block number, the total supply of STEEM, the number of STEEM vested into Steem Power, and other such key blockchain metrics.


image.png

This method is commonly used to report on the health of a blockchain, track its status, or report in real-time within applications. It is specifically useful for developers working with tools that need live data from a blockchain, such as a block explorer or dashboard.


image.png

This is the output of the method getDynamicGlobalProperties as I have run this script in the terminal and I have gotten this output. This method has returned all the global properties about the blockchain. It is showing the head block number, block id, current witness, total supply, vesting and delegation information.

Each of these provides insight into different aspects of the Steem blockchain:

  • getAccounts focuses on user-specific data.
  • getRewardFund gives information regarding the reward distribution mechanism.
  • getDynamicGlobalProperties provides a macro view of the blockchain's current state.


Calculate the effective SP for all Steemcurator accounts

To calculate the effective Steem Power (SP) for the Steemcurator accounts we analyze the critical data of the Steem blockchain. And by using this data we will calculate the effective vests and then we will convert the effective vests to the effective sp.

This calculation of the effective sp shows the net usable SP for each account. According to the given formula we will account the SP received through the delegation, SP delegated to other accounts and any ongoing power down withdrawals.

Effective SP is an important metric data and it represents the actual influence and the the power of the account in the blockchain. It enables the stakeholders to assess the role of the accounts within the ecosystem.


image.png
image.png

Formula for Effective SP

For the calculation of the effective vests I will use this given formula by the teacher: vesting_shares+received_vesting_shares-delegated_vesting_shares-vesting_withdraw_rate

Each component in the formula plays a distinct role:

  • vesting_shares: This component returns the base amount of SP inherently owned by the account.
  • received_vesting_shares: This shows the additional SP received through delegations from other accounts.
  • delegated_vesting_shares: This is the SP that the account has delegated out to other users or entities.
  • vesting_withdraw_rate: This is the portion of SP being withdrawn during a power down process.

The formula calculates the net effective VESTS from which the effective sp is caluclated. It represents the raw data of vesting shares. These VESTS are then converted into SP to reflect the usable power of the account in terms of blockchain influence.

Process of Calculation

  1. Data Retrieval: The process begins by fetching account details using the getAccounts method of the Steem API. This step provides the raw values for vesting_shares, received_vesting_shares, delegated_vesting_shares, and vesting_withdraw_rate for each of the Steemcurator accounts.

  2. Effective VESTS Calculation: By using the formula the net effective VESTS are computed for each account. The raw data which includes the "VESTS" unit is then processed and converted into numerical values to enable arithmetic operations.

  3. Conversion to SP: The calculated effective VESTS are converted into SP using the VESTS to SP ratio. And this is obtained from the getDynamicGlobalProperties method. This ratio is calculated as:

1VEST= total_vesting_fund_steem / total_vesting_shares

By multiplying the effective VESTS by this ratio provides the equivalent SP. In this way it makes the data more meaningful in terms of blockchain operations.


image.png

The results are presented in two forms for the distinction between the presentation of the VESTS and SP. The effective VESTS and the corresponding SP for each account is displayed in the table form. This dual representation provides a clear understanding of both the raw vesting shares and their impact in terms of Steem Power.

The effective SP is vital for understanding the role of the account on the Steem blockchain. The effect of the voting weight is determined by the effective steem power. It is the steem power which allows us to contribute on the platform because each transaction requires bandwidth and it is determined by the SP. Moreover if we have steem power in our account we can delegate it to others.

This is the calculation for the steemcutraor0x accounts and similarly if we want to calculate the amount of the effective sp or vests we can calculate just by replacing the account name. We can calculate effective sp of any account through this method.



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

The getDynamicGlobalProperties method returns a snapshot of the current state of the Steem blockchain by returning updated key metrics with each block. The properties are fundamental to knowing the health, capacity, and economic status of the blockchain. Analysis of the values allows developers, investors, and users to make better decisions about interacting with the blockchain and assessing its overall performance.


image.png
image.png

Here is the detail of all the properties from the given url:

  1. Head Block Number:
    It refers to the block which carries the latest addition of a blockchain. It keeps the users informed of the location of their blockchain. Monitoring the number of head block can therefore update a user as to what has occurred within his network.

  2. Current Supply:
    This is the total amount of STEEM in circulation. This will include all the STEEM tokens ever created or mined to date minus permanently removed. The current supply of this knowledge is essential in any economic analysis including how to go about determining inflation and the token distribution.

  3. Total Vesting Fund STEEM and Total Vesting Shares:
    These two values are crucial in defining the conversion of VESTS which is an expression of staked STEEM to Steem Power (SP). Total vesting fund is an accumulation of STEEM that back every SP and total vesting shares. These values express the overall engagement of the stakeholders and their confidence in the ecosystem.

  4. SBD Interest Rate:
    Presents the annual interest rate available for SBD holders. A higher interest rate rate increases the incentive for users to HODL SBD, which leads to stability and utility within its network. This makes it imperative to measure a blockchain's economic incentives.

  5. Last Irreversible Block Number:
    Marks the last block confirmed to be irreversible because of adequate confirmations in the network. All transactions made in and prior to this block are permanent. It assures the people about the safety of transactions and the reliability of the network.

  6. Current Witness:
    This identifies the active witness producing the current block. Witnesses play a pivotal role in maintaining the blockchain by validating transactions and adding blocks. This is information valuable for tracking governance and activity.

  7. Virtual Supply:
    This would reflect the theoretical total supply of the blockchain. This consists of STEEM that had been issued through the mechanism of SBD debt. This number reflects a much more comprehensive view of the networks economy. It includes both kinds of STEEM whether circulating or virtual.

  8. Maximum Block Size:
    This is the maximum size a block can be in bytes. This property defines the maximum transaction data that can be accommodated in a single block. It helps the developers to optimize applications to avoid reaching limits.

  9. Time:
    It represents the current blockchain time in UTC format. And this is needed for synchronizing blockchain activities with real world operations. Scheduling and verifying transactions or any other events require an accurate timestamp.

Aggregation of these properties in one API call gives users an extensive understanding of the Steem blockchain's real-time dynamics to help developers improve their applications, analysts monitor network health, and stakeholders make informed decisions.



All the three tasks in one video



I invite @wilmer1988, @josepha, @wuddi to join this learning challenge.



Sort:  
Loading...

Upvoted! Thank you for supporting witness @jswit.

Loading...

Coin Marketplace

STEEM 0.25
TRX 0.27
JST 0.040
BTC 96876.24
ETH 3451.68
SBD 1.58