steem-python for dummies #6 - Delegating

in #utopian-io7 years ago (edited)


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

Sort:  

Thanks for your post! I have a question btw. How could I know who I am delegating with the python-steem? Thanks in advance.

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

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.

.

I dont know about it. Will have a look if its possible though.

You can try asking it at steemdevs discord channel meanwhile.

Thank you.

.

Thank you for the contribution. It has been approved.

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

thank you very helpful tutorial

Hey @emrebeyler I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • You are generating more rewards than average for this category. Super!;)
  • Seems like you contribute quite often. AMAZING!

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

Want to stay on top of your game? You should definitely start learning AI @neurallearner

Birthdaypost !BEER



BEER Hey @emrebeyler, here is a little bit of from @isnochys for you. Enjoy it!