steem-python for dummies #6 - Delegating


Hello,

This is the 6. post of "steem-python for dummies" series. If you didn't read the older ones take your time and have a look.

  1. steem-python for dummies #1 - Introduction and Basic Operations
  2. steem-python for dummies #2 - Playing with account data
  3. steem-python for dummies #3 - Coding an upvote bot
  4. steem-python for dummies #4 - Private Memos
  5. steem-python for dummies #5 - Bundling Blockchain Operations

In this post, we will learn about creating delegations with steem-python.

Delegating

With the Hard fork 18, steem accounts gained a new ability to delegate their steem power. (SP)

I won't dive into details about the specs of delegation. If you're clueless about it, pay a visit to this post to learn the details.

Current tools to delegate

Steemit doesn't support delegation via Condenser. You can use well-known steemconnect to delegate SP or other 3rd party tools.

However, you don't need to use 3rd party services to create/remove delegations. steem-python already covered that operation well.

Creating delegations

All process can be done in two steps:

  • Convert SP to VESTS
  • Create a delegate_vesting_shares operation and broadcast it to the network.

Converting SP to VESTS is really easy with steem-python. You have a Converter class to do it.

s = Steem(nodes=["https://rpc.buildteam.io"],
          keys=["privkey_active"])
vests = '{} VESTS'.format(Converter().sp_to_vests(5))
s.delegate_vesting_shares('ned', vests, account="emrebeyler")

That's it.

steemd representation of the delegation. I hope he will use it wisely. I don't have much SP.

Removing delegations

Steem blockchain has a convention on operations, you do set weights to 0 if you want to reverse an operation. Like vote. That's the same, in order to cancel the delegation we will use the same operation but set the vests as 0.

s = Steem(nodes=["https://rpc.buildteam.io"],
          keys=["privkey_active"])
vests = '{} VESTS'.format(Converter().sp_to_vests(5))
s.delegate_vesting_shares('ned', vests, account="emrebeyler")

Removed my 5 SP delegation for ned. I want it back. Sorry.

Converting SP to VESTS

Even though steem-python handles the conversion here, let's find out how it really does under the hood.

Calculation steps for converting SP to VESTS.

steem daemon has a method named as get_dynamic_global_properties which returns useful info about latest state of the network.

What we need from that call are:

  • total_vesting_fund_steem
  • total_vesting_shares
from steem.amount import Amount
info = s.get_dynamic_global_properties()
total_vests = Amount(info["total_vesting_shares"]).amount
total_vesting_fund = Amount(info["total_vesting_fund_steem"]).amount

I have them in variables now. In order to find steem per vest ratio, I will divide total_vests to total_vesting_fund.

total_vests / total_vesting_fund
Out[21]: 2052.432100474714

Now, I have the steem per vest value. Let's multiply with the SP amount I delegated earlier in this post.

In [22]: 5 * total_vests / total_vesting_fund
Out[22]: 10262.16050237357

Numbers match with the Converter's calculation.


That's all for this post. Feel free to ask questions or request topics about steem-python for the incoming posts.



Posted on Utopian.io - Rewarding Open Source Contributors

H2
H3
H4
3 columns
2 columns
1 column
12 Comments