nuagnorab
nuagnorab

I blog about some tech, some web dev, and funny things.

Learn Steem & Hive API - #01 - 轉化 vesting_shares 為 SP or HP


喜歡開源軟件。 因為沒有人擁有它,每個人都可以努力使它變得更好。我希望有一天像Likeers這樣的Likecoin前端可以開源。

無論如何,我想與您分享我學習Steem / Hive API時遇到的事情。

從我在Steem上的第一天開始,我一直想學習如何在沒有前端應用程序的幫助下直接與他人進行區塊鏈交流。

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

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


I love open source software. Because not one owns it and everyone can work to make it better.

I wish Likecoin frontend like Matters can be open source someday.

Anyway, I want to share with you something I encountered when learning Steem / Hive API.

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!



For Steem, I start with the steem-python from [Github repo](https://github.com/steemit/steem-python) by @steemit.

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

For Hive, I start with forked hive-python from [Github repo](

https://github.com/pharesim/hive-python) 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.



## Installation

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 starting to get 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

vests2hp(ac_info['vesting_shares'])

```



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 了。


Cheers!

此文章在 Likecoin, Steem 和 Hive 鏈上齊發。

CC BY-NC-ND 2.0 版权声明

喜欢我的文章吗?
别忘了给点支持与赞赏,让我知道创作的路上有你陪伴。

加载中…

发布评论