How to calculate Steem power

in #utopian-io7 years ago (edited)

Hi friends,

In this tutorial I'll show you how to calculate the steem power of an account with actual values.

NodeJs modules required

To calculate the current steem power of an account, you need to get some data first. Get the account data for the account you want to calculate steem power. Get latest block and conversion info.

  • steem.api.getAccounts
    Use this method to get the account data.
    Selection_053.png

  • steem.api.getDynamicGlobalProperties
    Get global data.
    Selection_054.png

  • steem.api.getBlockHeader
    Selection_055.png

  • steem.api.getRewardFund
    We need to know what is the current amount of steem funds to get an idea of the available stock and is required to get the total vests amount for the account.
    Selection_056.png

  • steem.api.getCurrentMedianHistoryPrice
    With this function we will get the current price to calculate vests for the account.
    Selection_057.png

  • steem.formatter.vestToSteem
    Use this to format total vest t a human readable number
    Selection_058.png

Code should look similar to this

Selection_059.png
Selection_063.png

Code in text

const
  wait = require('wait.for'),
  steem = require('steem');

wait.launchFiber(function() {
  // Get account data
  var account = wait.for(
    steem.api.getAccounts,
    ['raserrano']
  );

  // Get global data
  var globalData = wait.for(
    steem.api.getDynamicGlobalProperties
  );

  // Get conversion information
  var ci = new Object();
  // Get latest head block
  var headBlock = wait.for(
    steem.api.getBlockHeader,
    globalData.head_block_number
  );

  ci.rewardfund_info = wait.for(
    steem.api.getRewardFund,
    'post'
  );

  ci.price_info = wait.for(
    steem.api.getCurrentMedianHistoryPrice
  );

  ci.reward_balance = ci.rewardfund_info.reward_balance;
  ci.recent_claims = ci.rewardfund_info.recent_claims;
  ci.reward_pool = ci.reward_balance.replace(' STEEM', '')
    / ci.recent_claims;

  ci.sbd_per_steem = ci.price_info.base.replace(' SBD', '')
    / ci.price_info.quote.replace(' STEEM', '');

  ci.steem_per_vest =
    globalData.total_vesting_fund_steem.replace(' STEEM', '')
    / globalData.total_vesting_shares.replace(' VESTS', '');

  var vp = account[0].voting_power;
  var vestingSharesParts = account[0].vesting_shares.split(' ');
  var receivedSharesParts = account[0].received_vesting_shares.split(' ');
  var delegatedSharesParts = account[0].delegated_vesting_shares.split(' ');
    var totalVests =
    parseFloat(vestingSharesParts[0]) + parseFloat(receivedSharesParts[0]) -
    parseFloat(delegatedSharesParts[0]);

  var steempower = steem.formatter.vestToSteem(
        totalVests,
        parseFloat(globalData.total_vesting_shares),
        parseFloat(globalData.total_vesting_fund_steem)
      );

  console.log('Total steem power is: ' + steempower);
  process.exit();
});

Results of executing the code:
Selection_062.png

You can compare the results with the Effective SP from: https://steemd.com/@raserrano
After processing the vesting shares, delegated and received,
Selection_064.png
You should be able to see the Effective SP
Selection_065.png



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Coding Sorcery.....Jajajaja!

Nicely done :)

Thanks buddy :D

Hey @raserrano I am @utopian-io. I have just upvoted you at 4% Power!

Achievements

  • Seems like you contribute quite often. AMAZING!

Suggestions

  • Work on your followers to increase the votes/rewards. My vote is on the human input. Good luck!
  • Contribute more often to get higher and higher rewards. I want to see you often!
  • Wondering why other contributions got more? I introduced a competition factor. My vote is based also on how competitive the category used is.

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Qurator
Your Quality Content Curator
This post has been upvoted and given the stamp of authenticity by @qurator. To join the quality content creators and receive daily upvotes click here for more info.

Qurator's exclusive support bot is now live. For more info click HERE or send some SBD and your link to @qustodian to get even more support.

Thank you for your contribution.
In order to approve, there are few adjustments needed:
The screenshot below "steem.formatter.vestToSteem" appears to include the wrong reference/code.
Also could you provide sample results of running your code? and comparing those to actual SP values? such as for example your account?

You may edit your post here, as shown below:

You can contact us on Discord.
[utopian-moderator]

Sure thing, I will add that thanks for your comment.

Thank you I've updated the post.

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Coin Marketplace

STEEM 0.17
TRX 0.15
JST 0.028
BTC 56677.48
ETH 2329.02
USDT 1.00
SBD 2.36