How to calculate Steem power
Hi friends,
In this tutorial I'll show you how to calculate the steem power of an account with actual values.
NodeJs modules required
- steem: Steem-JS official library. Official page
- wait.for: Wait.for will help in the async calls. Official page
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.
steem.api.getDynamicGlobalProperties
Get global data.
steem.api.getBlockHeader
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.
steem.api.getCurrentMedianHistoryPrice
With this function we will get the current price to calculate vests for the account.
steem.formatter.vestToSteem
Use this to format total vest t a human readable number
Code should look similar to this
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:
You can compare the results with the Effective SP from: https://steemd.com/@raserrano
After processing the vesting shares, delegated and received,
You should be able to see the Effective SP
Posted on Utopian.io - Rewarding Open Source Contributors
Coding Sorcery.....Jajajaja!
Nicely done :)
Thanks buddy :D
Hey @raserrano I am @utopian-io. I have just upvoted you at 4% Power!
Achievements
Suggestions
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
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
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]