Learn Steem & Hive API - #01 - 轉化 vesting_shares 到 SP or HP | convert vesting shares to SP/HP

in hive-180932 •  6 days ago 

What's up guys,

Ever since day 1 of my life on Steem, I have been wanted to learn how to interact with people or the blockchain directly without any help from frontend applications.

It has been an opportunity for me to finally push myself into this rabbit hole since many friends in the community were talking about the HIVE's API. Especially those times when the Hive's wallet was not available (It is working now).

Having said that, I would like to learn more about Steem / Hive's API as well. Since I have been told they are almost identical except for the naming. Learning one side will definitely earn how to interact with the other. One stone kill two bird, clearly a very good deal!


由於社區中許多朋友都在談論HIVE的API,我見有人把hive api Github 轉發出來,便借此機會來了解一下。 特別是在Hive的錢包不可使用的時候(現在正常可用了)。

我也想進一步了解Steem / Hive 的API。 我被告知,除了 library 的名字外,它們幾乎完全相同。 學習一邊肯定可以在另一邊使用上。 一石二鳥,顯然是很劃算的!

For Steem, I start with the steem-python from Github repo by @steemit.

Steem 我用了 steemit 官方發佈的 GitHhub.

For Hive, I start with forked hive-python from Github repo by @pharesim.

至於,Hive 我用了 @pharesim 發佈的 GitHub.

Little Intro here.

steem-python is the official Steem library for Python. It comes with a BIP38 encrypted wallet and a practical CLI utility called steempy.

hive-python is a Hive library for Python. It comes with a BIP38 encrypted wallet and a practical CLI utility called hivepy.


First, we need to install the python package from source. You can do

首先,我們需要安裝python軟件包。 你可以在 CLI 上如此安裝

pip3 install steem # for steem-python
pip3 install hivepy  # for hive-python

It is getting too wordy, I will be using hive as the example since they are identical.

We need to import the installed library

from hive import Hive
from hive.converter import Converter
h = Hive()

ac_info = h.get_account(username)

def vests2hp(vests_count):
  vests_count = float(vests_count.replace(' VESTS', ''))
  converter = Converter(hived_instance = h)
  hp_count = vests_count / 1e6 * converter.hive_per_mvests()
  return ('{:.3f}'.format(hp_count))

# This will return you the amount of SP/HP that your are holding

The main point is to get the calculation right in order to show the correct numbers.


  hp_count = vests_count / 1e6 * converter.hive_per_mvests()

You will need to get the hive_per_mvests from the blockchain at the time being for the correct calculation which is to divide the product of 1e6 (1 X10^6) and the hive_per_mvests().

您需要當時從區塊鏈中獲取當時hive_per_mvests()的數值才能進行正確計算,再除以1e6(1 X10 ^ 6)hive_per_mvests``的乘積

Now that we know how to calculate vesting shares. Let's see what we will learn about next time.

現在,我們知道如何轉化 vesting_shares 到 SP or HP 了。


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:  



Hi @nuagnorab!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your UA account score is currently 3.544 which ranks you at #4204 across all Steem accounts.
Your rank has improved 241 places in the last three days (old rank 4445).

In our last Algorithmic Curation Round, consisting of 124 contributions, your post is ranked at #59.

Evaluation of your UA score:
  • You're on the right track, try to gather more followers.
  • The readers like your work!
  • Try to work on user engagement: the more people that interact with you via the comments, the higher your UA score!

Feel free to join our @steem-ua Discord server