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

in steemjs-s22w2 •  10 days ago 

Hello everyone! Today I am here to participate in the Domain Steem with JavaScript course by @alejos7ven. It is about learning the Steem API. If you want to join then:



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



Blue and Yellow Geometric Programmer Presentation.png

Designed with Canva

Use Steem JS to execute at least 3 methods from Steem API [2 PTS]

As we need to interact with the Node.js scripts so we must have Node.js installed in our system. In order to download simply go to the Node.js.


image.png

Here on the main screen we can see the LTS version of node.js and it is the stable version so download it.

image.png

Here you can see after downloading I have installed it in my system.

For the confirmation of the installation I have run the commands node -v and npm -v in the terminal and It was successfully installed as the commands worked and provided the details of the version.

Then in order to install the Steem JS I followed these steps:

  • I run the command to create a directory mkdir steem-js-project.
  • Then I opened the directory by this command cd steem-js-project.
  • Then I initialized the package with package.json by using this command npm init -y.
  • Now this is the last step for the installation of the Steem JS library by using this command npm install steem --save.
  • It added a new folder with all the dependencies and information about the Steem JS library and it told me steem version as well which is steem": "^0.7.11.

Now we are all set to use the library to perform the operations.

Method 1 = Fetch Block Information: getBlock
image.png

This is the getBlock method from the Steem API. With the help of this method we can fetch the details of the block. A block is a sum of all the transaction happening in the block and the information of the block validator or we can say the miner or witness in the steem ecosystem. This method provides the following details:

  • Previous block
  • Timestamp
  • Witness
  • Transaction_merkle_root
  • Extensions
  • Witness_signature
  • Transactions
  • Block id
  • Signing key
  • Transactions_ids

We can get the information of any block by writing its number in the code. I have shown it with the example in the video by showing the information of the different blocks by updating the block number in the code.

Method 2 = Fetch Account Information: getAccounts


image.png

This is the getAccountsmethod of Steem API. This is a unique and very informative method which helps us to get all the details of the account which we specified in the code. It fetch all the information of the specific account from the Steem API. It provides us the following details of the account:

  • Id
  • Name
  • Keys information
  • Account Balance information
  • Authentication information
  • Witness vote information
  • Post
  • comments
  • Account recovery

Along with the above information it provides other extensive details as well.

Here in the video you can see while changing the name of the account we can get the information associated with that account from the Steem API. We can get information of any account with this method.

Method 3 = Fetch Blockchain Properties: getDynamicGlobalProperties


image.png

This is the getDynamicGlobalProperties method of Steem API. This method provides the detail information of the blockchain properties. We can get the global properties and information regarding the steem blockchain by using this method of Steem API. This method or function provides us the following information related the blockchain:

  • head_block_number: 91540950
  • head_block_id: 0574cdd6482b488aec870d7463f654b971cc3ccb
  • time: 2024-12-25T13:55:21
  • current_witness: steem.history
  • total_pow: 514415
  • num_pow_witnesses: 172
  • virtual_supply: 532637992.773 STEEM
  • current_supply: 479374193.856 STEEM
  • confidential_supply: 0.000 STEEM
  • init_sbd_supply: 0.000 SBD
  • current_sbd_supply: 13915666.580 SBD
  • confidential_sbd_supply: 0.000 SBD
  • total_vesting_fund_steem: 182313670.131 STEEM
  • total_vesting_shares: 308123431458.675178 VESTS
  • total_reward_fund_steem: 0.000 STEEM
  • total_reward_shares2: 0
  • pending_rewarded_vesting_shares: 767206808.185346 VESTS
  • pending_rewarded_vesting_steem: 409071.308 STEEM
  • sbd_interest_rate: 0
  • sbd_print_rate: 0
  • maximum_block_size: 65536
  • required_actions_partition_percent: 0
  • current_aslot: 92099907
  • recent_slots_filled: 340282366920938463463374607431000000000
  • participation_count: 127
  • last_irreversible_block_num: 91540935
  • vote_power_reserve_rate: 10
  • delegation_return_period: 432000
  • reverse_auction_seconds: 300
  • available_account_subsidies: 19393088
  • sbd_stop_percent: 1000
  • sbd_start_percent: 900
  • next_maintenance_time: 2024-12-25T14:45:24
  • last_budget_time: 2024-12-25T13:45:24
  • content_reward_percent: 6500
  • vesting_reward_percent: 1500
  • sps_fund_percent: 1000
  • sps_interval_ledger: 15.840 SBD
  • downvote_pool_percent: 2500

I have run this method in the terminal and it has provided me all this information currently. So this method is helpful to fetch the data regarding the properties of the blockchain.



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

We can calculate the effective sp of any account by using the Steem API. According to the task requirement I will show calculating the effective sp of the sc01 - sc08 accounts. In the steemit platform SP or steem power is an important asset which drives the platform. This is the amount of staked steems. So in order to calculate the SP of the sc01 - sc08 accounts first of all we need to have formula which can be used to calculate the effective sp.

Effective SP=vesting_shares+received_vesting_shares−delegated_vesting_shares−vesting_withdraw_rate

So this is the formula which I will implement for the calculation of the effective sp. I will access the attributes related to sp as mentioned in the formula by using the Steem API. I will use the the global properties of the account and then I will call the method getAccounts to get the details of the account.

Then I will convert the vest to the sp by using the Steem blockchain's total_vesting_fund_steem and total_vesting_shares.

Here is the detailed information of the program:

image.png

First of all I have imported the steem library to perform all of its functions.

image.png

Then I have defined an array with the name accounts as constant where all the steemcurator0x accounts are defined. And here each account will be queried via the Steem API.

image.png

Then here is the function to fetch the global properties by using the Steem API. This global properties include total_vesting_fund_steem and total_vesting_shares. These are necessary for the conversion of the VESTS to the SP.


image.png

This method is also useful in this task. This method fetches the details like vesting shares, delegated shares, etc. of multiple accounts. It uses getAccounts API call with the list of account names. And this return an array of account data objects.

image.png

This converts the vests shares to sp by using the formula. Here is the information of the parameters which are being used in the above formula:

  • vestingShares: The account's vesting shares (numeric).
  • totalVestingShares: Total vesting shares on the blockchain (global).
  • totalVestingFundSteem: Total STEEM in the vesting fund (global).

image.png

This is the main function. In this main function there is the usage of the try and catch method. In the try all the functions are called to get the global properties, account details and totalVestingFundSteem.

Then the details of the account are fetched. After that there is the code to calculate the effective SP of the each account. Then there is the implementation of the formula for the calculation of the effective sp.

And in the catch method there is the exception handling that if any error occurs then it will print that error with all its information so that the user can understand the error and fix that.

Here is the effective calculated SP of all the accounts by using the Steem API:

  • Account: steemcurator01

    • Effective SP: 13,380,421.331 SP
  • Account: steemcurator02

    • Effective SP: 6,592,085.880 SP
  • Account: steemcurator03

    • Effective SP: 1,260,092.569 SP
  • Account: steemcurator04

    • Effective SP: 732,379.087 SP
  • Account: steemcurator05

    • Effective SP: 742,167.176 SP
  • Account: steemcurator06

    • Effective SP: 756,908.604 SP
  • Account: steemcurator07

    • Effective SP: 747,931.815 SP
  • Account: steemcurator08

    • Effective SP: 752,808.997 SP

Here if you notice in the code I have converted the effective sp vests to the steem power.



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 get_dynamic_global_properties method in Steem is a crucial API function. This function fetches real time information of the blockchain. It provides extensive details. Its details range from the latest block information to the current economic status of the network. We can get a complete overview of the blockchain network through this method.

This get_dynamic_global_properties is especially important for the developers and witnesses. Moreover this method is also very helpful for the stakeholders of the blockchain network who require an updated view of the blockchain status. They can utilize it for the governance, monitoring and the development process. SO this method is of great importance while providing the real time information about the blockchain network.

Here are the 5 values from this method:


image.png

Here you can see I have fetched the real time information of the 5 values from this method. This is real time data and each time we interact with these values we get the real time and current data. Each time I run this code I got a new data with a different steem witness.

Here is the detailed explanation of these five key values which I have used from this method. Their significance and examples are given below for the better understanding for everyone.

1. Head Block Number

This is the block number which has been added recently to the blockchain. This recently added block represents the current state of the blockchain in terms of block progression. It is necessary to ensure that the nodes are synchronized with the latest state of the chain. We can it for the debugging purpose as well or to analyze the activities which are related to the block.

For example as I have run the code to check the status of head block I have gotten this value 91544531. It indicates the blockchain is currently at block 91,544,531.

A developer who is running a Steem node can check this value to confirm that their node is up to date.


2. Current Witness

This value from this method helps to get the information or the username of the current witness at the block. It shows which witness is currently responsible for producing the block. The witnesses are the selected account who validate and sign the blocks. We know that these witnesses are selected by the community based on their work in the top.

This value helps us to identify the current witness for the production of the block. It ensures transparency in the production of the block. It also helps to track the governance activity. In the above output of the code @stmpak.wit is the current witness who is responsible for the production of the block.

This value helps the stakeholders to know that which witness is currently active and contributing to the production of the block.


3. Total Vesting Fund Steem

This value represents the total amount of STEEM tokens locked in the vesting pool. And this amount is used for the steem power. This represents the pool of STEEM dedicated to the governance and voting power. It determines how much SP a user recieves per unit of vesting shares. For example 182344648.673 STEEM represents that this amount of steems is locked for the vesting.

With the help of this key value the developers can calculate the SP equivalent of a user's vesting shares using this value. The stakeholders can measure that how much token supply is committed for the long term participation.


4. Total Vesting Shares

This key value in this method shows the total number of vesting shares distributed across all accounts. Vesting shares are the internal representation of the SP. The ratio of the Total Vesting Fund Steem to Total Vesting Shares determines the SP per vesting share. For example 308172976074.017707 VESTS shares exists currently when I run this code.

This key value is used with the combination of the vesting fund to calculate the SP of the user and the influence of the vote. It also helps to track the overall allocation of the voting power on the blockchain.


5. Current Supply

This is another important key value of the method get_dynamic_global_properties. This shows the total amount of STEEM tokens currently in the circulation. It includes the liquid STEEM and all those STEEM which are locked in the vesting. This key value provides information about the token economy of the blockchain. It shows the inflation and the growth of the token supply.

For example at the time of running the code the current supply of STEEM is 479384063.097 STEEM. So it shows these STEEM are currently in the circulation.

We can use this key value to evaluate the token distribution as well as the impact of the inflation on the economy. It helps the developers and stakeholders to estimate the potential liquidity of the market.


Additional Key Values for Context

  1. Head Block ID: Hash of the most recent block, useful for verifying block integrity.
  2. Last Irreversible Block Number: The highest block guaranteed to be finalized and irreversible.
  3. SBD Supply: Total amount of Steem Backed Dollars (SBD) in circulation, indicating the platform’s stablecoin economy.
  4. Maximum Block Size: The upper limit for block size, affecting transaction capacity.
  5. Participation Count: Tracks witness participation in block production.

The get_dynamic_global_properties method is necessary for monitoring the status and health of the Steem blockchain. Its values provide critical insights into governance, economics and technical operations.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  
Loading...