Steem Developer Portal

In this tutorial we show you how to delegate a portion of an accounts available VESTS (STEEM POWER) to another user on the Steem blockchain using the commit class found within the steem-python library.

Intro

The Steem python library has a built-in function to transmit transactions to the blockchain. We are using the delegate_vesting_shares method found within the commit class in the library. When you delegate power you make a portion of your VESTS available to another user. This can empower an application, author, or curator to make higher votes. Before we do the delegation, we use the get_account function to check the current VESTS balance of the account to see what is available. This is not strictly necessary but adds to the useability of the process. It should be noted that when a delegation is cancelled the VESTS will only be available again after 7 days. The delegate_vesting_shares method has 3 parameters:

to_account - The account we are delegating shares to (delegatee)

vesting_shares - The amount of VESTS to delegate. This is required to be a string value

Because this tutorial alters the blockchain we connect to a testnet so we don’t create spam on the production server.

2. User information and steem node

We require the private active key of the user in order for the transaction to be committed to the blockchain. This is why we are using a testnet. The values are supplied via the terminal/console before we initialise the steem class. We also check if the user name provided is active on the chain. There are some demo accounts available but we encourage you to create your own accounts on this testnet and create balances you can delegate.

3. Check balance

In order to give the user enough information to make the delegation we check the current VESTS balance of the account using the get_account function. We also display a list of currently active delegations should the user choose to remove a delegation. You can refer to tutorial 29_get_delegations_by_user to see how this is done.

4. Delegation amount and commit

Both the vesting_shares and the to_account parameters are assigned via input from the terminal/console. The user is given the option to delegate power to or remove a currently active delegation from another user. We also check the to_account to make sure it’s a valid account name.

Any amount of VESTS delegated to a user will overwrite the amount of VESTS currently delegated to that user. This means that to cancel a delegation we transmit to the blockchain a vesting_shares value of zero. The inputs and function execution is based on the users choice. If you are using one of Steemit’s demo accounts, please leave some VESTS for others to delegate!

if(option=='DELEGATE POWER'):vesting_value=input('Please enter the amount of VESTS to delegate: ')vesting_shares=(str(vesting_value)+' VESTS')client.delegate_vesting_shares(to_account=delegatee,vesting_shares=vesting_shares,account=username)print('\n'+str(vesting_shares)+' have been successfully been delegated to '+delegatee)else:vesting_shares='0 VESTS'client.delegate_vesting_shares(to_account=delegatee,vesting_shares=vesting_shares,account=username)print('Delegated VESTS have been successfully removed from '+delegatee)

A confirmation of the transaction is displayed on the UI.

We encourage users to play around with different values and data types to fully understand how this process works. You can also check the balances and transaction history on the testnet portal.