create account

Part 24: An In Dept Look At Steem Operation Types Part I by steempytutorials

View this thread on: hive.blogpeakd.comecency.com
· @steempytutorials ·
$37.47
Part 24: An In Dept Look At Steem Operation Types Part I
<center>![steem-python.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1515886103/kmzfcpvtzuwhvqhgpyjp.png)</center>

This tutorial is part of a series where different aspects of programming with `steem-python` are explained. Links to the other tutorials can be found in the curriculum section below. This part is a direct continuation of [Part 23: Retrieve And Process Full Blocks From The Steem Blockchain](https://steemit.com/utopian-io/@steempytutorials/part-23-retrieve-and-process-full-blocks-from-the-steem-blockchain) and will go into more detail following `operation types`: `transfer`, `transfer_to_vesting`, `withdraw_vesting` and `convert`.


---
#### Repository
https://github.com/steemit/steem-python

#### What will I learn

- How to access data in a operation
- What is a transfer?
- What is a transfer_to_vesting
- What is a withdraw_vesting
- What is a convert?

#### Requirements

- Python3.6
- `steem-python`

#### Difficulty

- basic

---

### Tutorial

#### Setup
Download the files from [Github](https://github.com/amosbastian/steempy-tutorials/tree/master/part_24). There 2 are files `get_blocks.py` which contains the code. The main file takes 3 arguments from the command line which sets the `starting_block`, `block_count` and what `operation` to filter for.

Run scripts as following:
`> python get_block.py 22224731 10 transfer`

#### How to access data in a operation
The previous tutorial went into great detail how to extract `operations` from `blocks`. There are 19 different `operations` in total and each has a different structure. However, the data for the `operation` is always stored in the same spot.

```
{
	'ref_block_num': 8004,
	'ref_block_prefix': 1744181707,
	'expiration': '2018-05-07T15:29:54',
	'operations': [
		['vote', {
			'voter': 'acehjaya',
			'author': 'zunaofficial79',
			'permlink': 'kabut-pagi',
			'weight': 10000
		}]
	],
	'extensions': [],
	'signatures': ['1f205086670c27365738697f0bc7cfde8b6e976608dc12b0d391b2b85ad7870a002313be4b09a358c30010be2a09bebacead866ba180afc348ce40c70566f4ed88']
}
```
<br>
Under `operations` is an array, the first index is the `operation type` and the second index is a `json table` with the `operation data`.
```
if transaction['operations'][0][0] == self.tag:
    self.process_operation(transaction['operations']
                           [0][1],
                           self.tag)
```
Filter for the required operation type and process the `json data`. For this example tutorial a different `class` is made for each `operation type` which stores the data in respective `variables` and has a `print function`. These classes can be found in the `operations.py` file.

#### What is a transfer?
Every `transfer` of either `Steem` or `SBD` between two different user accounts is a `transfer` operation. This operation has 4 variables. `from` is the account that sends the funds, `to` the receiving account, `amount` the valuation and which currency, and optionally `memo`. In which messages can be added.

```
{
	'from': 'yusril-steem',
	'to': 'postpromoter',
	'amount': '5.000 SBD',
	'memo': 'https://steemit.com/life/@yusril-steem/our-challenges-and-trials-in-life'
}
```
<br>
By using a `class` to process the `operation` all the `variables` can be neatly kept and additional `functions` can be added as well. Like the `print_operation()` which allows for easy printing to the terminal. A separate `class` is made for each of the `operations` discussed in this tutorial.
```
class Transfer():
    def __init__(self, operation, block, timestamp):
        self.account = operation['from']
        self.to = operation['to']
        self.amount = operation['amount']
        self.memo = operation['memo']
        self.block = block
        self.timestamp = timestamp

    def print_operation(self):
        print('\nBlock:', self.block, self.timestamp)
        print('Operation: transfer')
        print('From:', self.account)
        print('To:', self.to)
        print('Amount:', self.amount)
        print('Memo:', self.memo)
        print('')
```
<br> 
Additional data that normally falls outside the scope of the `operation` can also be stored in the `class`. Like the `block` in which the `operation` took place and the timestamp of the `operation`. 

#### What is a transfer_to_vesting
A `power up` of `Steem` by a user is known as a `transfer_to_vesting` and contains 3 `variables`. `from` the user account itself, `to` the receiving account and `amount` the amount being powered up. This `operation` locks up the `Steem` for 13 weeks.  

```
{
	'from': 'flxsupport',
	'to': 'ltcil',
	'amount': '0.719 STEEM'
}
```
<br>

#### What is a withdraw_vesting

Opposite to a `transfer_to_vesting` is a `withdraw_vesting`. When a user initiates a `power down` the amount of `steem power` will be powered down in 13 weekly increments. `Vested steem power` is displayed in `VESTS` and has to be converted to `Steem` based on the current conversion rate. This is outside the scope of this tutorial but can be found [here](https://steemit.com/utopian-io/@steempytutorials/part-22-calculate-account-value-based-on-current-market-prices-via-api). This `operation` holds 2 different `variables`. `account` the user account and `vesting_shares` the amount of `VESTS` to be converted to `Steem` at the time of the operation.


```
{
	'account': 'bazimir',
	'vesting_shares': '44671.906021 VESTS'
}
```
<br>

#### What is a convert?
It is possible to convert `SBD` to `Steem` on the `internal market`. This `operation` assumes that the value of `SBD` is at $1.0, which may not be true. Always check the `external markets` before doing such an `operation`. After 3 days the `operation` matures and the user will receive the `Steem`. This `operation` holds 3 different `variables`: `amount` the amount of `SBD` to be converted, `owner` the account initiating the conversion and `requestid` the id for the system to perform the conversion after 3 days.

```
{
	'amount': '5000.0 SBD',
	'owner': 'steemit',
	'requestid': 1467592156
}
```
<br>

#### Running the script
Running the script will print the `operations`, for which the filter has been set, to the terminal starting from the `starting_block` for `block_count` amount of `blocks`. A `class` object is made for the `operation` and the build in `print_operation()` function is called. The data of the `operation` is printed to the terminal with the additional information of the `block` in which the `operation` is contained and the `timestamp` of the `operation`.

```
python get_blocks.py 22224731 10 transfer

Booted
Connected to: https://rpc.buildteam.io
Block: 22224731

Block: 22224731 2018-05-07T15:20:03
Operation: transfer
From: hottopic
To: jgullinese
Amount: 0.001 SBD
Memo: Hello Friend, Your post will be more popular and you will find new friends.We provide "Resteem upvote and promo" service.Resteem to 18.000+ Follower,Min 45+ Upvote.Send 1 SBD or 1 STEEM to @hottopic (URL as memo) Service Active


Block: 22224731 2018-05-07T15:20:03
Operation: transfer
From: minnowbooster
To: msena
Amount: 0.001 SBD
Memo: You got an upgoat that will be done by bycz,greece-lover,hemanthoj,percygeorge,bigdave2250,mexresorts,wanxlol,nickmorphew,thauerbyi,blackbergeron,aziz96,lovlu,utube,lowestdefinition. We detected an open value of 0.0$, worth 0.001 SBD in send and refunding that! Request-Id: 1176288
...
...
...
```



#### Curriculum
##### Set up:
- [Part 0: How To Install Steem-python, The Official Steem Library For Python](https://steemit.com/utopian-io/@amosbastian/how-to-install-steem-python-the-official-steem-library-for-python)
- [Part 1: How To Configure The Steempy CLI Wallet And Upvote An Article With Steem-Python](https://steemit.com/utopian-io/@steempytutorials/part-1-how-to-configure-the-steempy-cli-wallet-and-upvote-an-article-with-steem-python)
##### Filtering
- [Part 2: How To Stream And Filter The Blockchain Using Steem-Python](https://steemit.com/utopian-io/@steempytutorials/part-2-how-to-stream-and-filter-the-blockchain-using-steem-python)
- [Part 6: How To Automatically Reply To Mentions Using Steem-Python](https://steemit.com/utopian-io/@steempytutorials/part-6-how-to-automatically-reply-to-mentions-using-steem-python)
- [Part 23: Part 23: Retrieve And Process Full Blocks From The Steem Blockchain](https://steemit.com/utopian-io/@steempytutorials/part-23-retrieve-and-process-full-blocks-from-the-steem-blockchain)
##### Voting
- [Part 3: Creating A Dynamic Autovoter That Runs 24/7](https://steemit.com/utopian-io/@steempytutorials/part-3-creating-a-dynamic-upvote-bot-that-runs-24-7-first-weekly-challenge-3-steem-prize-pool)
- [Part 4: How To Follow A Voting Trail Using Steem-Python](https://steemit.com/utopian-io/@steempytutorials/part-4-how-to-follow-a-voting-trail-using-steem-python)
- [Part 8: How To Create Your Own Upvote Bot Using Steem-Python](https://steemit.com/utopian-io/@steempytutorials/part-8-how-to-create-your-own-upvote-bot-using-steem-python)
##### Posting
- [Part 5: Post An Article Directly To The Steem Blockchain And Automatically Buy Upvotes From Upvote Bots](https://steemit.com/utopian-io/@steempytutorials/part-5-post-an-article-directly-to-the-steem-blockchain-and-automatically-buy-upvotes-from-upvote-bots)
- [Part 7: How To Schedule Posts And Manually Upvote Posts For A Variable Voting Weight With Steem-Python](https://steemit.com/utopian-io/@steempytutorials/part-7-how-to-schedule-posts-and-manually-upvote-posts-for-a-variable-voting-weight-with-steem-python)
###### Constructing
- [Part 10: Use Urls To Retrieve Post Data And Construct A Dynamic Post With Steem-Python](https://steemit.com/utopian-io/@steempytutorials/part-10-use-urls-to-retrieve-post-data-and-construct-a-dynamic-post-with-steem-python)
##### Rewards
- [Part 9: How To Calculate A Post's Total Rewards Using Steem-Python](https://steemit.com/utopian-io/@steempytutorials/how-to-calculate-a-post-s-total-rewards-using-steem-python)
- [Part 12: How To Estimate Curation Rewards Using Steem-Python](https://steemit.com/utopian-io/@steempytutorials/part-12-how-to-estimate-curation-rewards)
- [Part 14: How To Estimate All Rewards In Last N Days Using Steem-Python](https://steemit.com/utopian-io/@steempytutorials/how-to-estimate-all-rewards-in-last-n-days-using-steem-python)
##### Transfers
- [Part 11: How To Build A List Of Transfers And Broadcast These In One Transaction With Steem-Python](https://steemit.com/utopian-io/@steempytutorials/part-11-how-to-build-a-list-of-transfers-and-broadcast-these-in-one-transaction-with-steem-python)
- [Part 13: Upvote Posts In Batches Based On Current Voting Power With Steem-Python](https://steemit.com/utopian-io/@steempytutorials/part-13-upvote-posts-in-batches-based-on-current-voting-power-with-steem-python)
##### Account Analysis
- [Part 15: How To Check If An Account Is Following Back And Retrieve Mutual Followers/Following Between Two Accounts](https://steemit.com/utopian-io/@steempytutorials/part-15-how-to-check-if-an-account-is-following-back-and-retrieve-mutual-followers-following-between-two-accounts)
- [Part 16: How To Analyse A User's Vote History In A Specific Time Period Using Steem-Python](https://steemit.com/utopian-io/@steempytutorials/part-16-how-to-analyse-a-user-s-vote-history-in-a-specific-time-period-using-steem-python)
- [Part 18: How To Analyse An Account's Resteemers Using Steem-Python](https://steemit.com/utopian-io/@steempytutorials/part-18-how-to-analyse-an-account-s-resteemers)
---

The code for this tutorial can be found on [GitHub](https://github.com/amosbastian/steempy-tutorials/tree/master/part_24)!

This tutorial was written by @juliank.
πŸ‘  , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
properties (23)
authorsteempytutorials
permlinkpart-24-an-in-dept-look-at-steem-operation-types-part-i
categoryutopian-io
json_metadata{"tags":["utopian-io","tutorials","steem-python","programming","python"],"users":["juliank"],"image":["https://res.cloudinary.com/hpiynhbhq/image/upload/v1515886103/kmzfcpvtzuwhvqhgpyjp.png"],"links":["https://steemit.com/utopian-io/@steempytutorials/part-23-retrieve-and-process-full-blocks-from-the-steem-blockchain","https://github.com/steemit/steem-python","https://github.com/amosbastian/steempy-tutorials/tree/master/part_24","https://steemit.com/utopian-io/@steempytutorials/part-22-calculate-account-value-based-on-current-market-prices-via-api","https://steemit.com/utopian-io/@amosbastian/how-to-install-steem-python-the-official-steem-library-for-python","https://steemit.com/utopian-io/@steempytutorials/part-1-how-to-configure-the-steempy-cli-wallet-and-upvote-an-article-with-steem-python","https://steemit.com/utopian-io/@steempytutorials/part-2-how-to-stream-and-filter-the-blockchain-using-steem-python","https://steemit.com/utopian-io/@steempytutorials/part-6-how-to-automatically-reply-to-mentions-using-steem-python","https://steemit.com/utopian-io/@steempytutorials/part-3-creating-a-dynamic-upvote-bot-that-runs-24-7-first-weekly-challenge-3-steem-prize-pool","https://steemit.com/utopian-io/@steempytutorials/part-4-how-to-follow-a-voting-trail-using-steem-python","https://steemit.com/utopian-io/@steempytutorials/part-8-how-to-create-your-own-upvote-bot-using-steem-python","https://steemit.com/utopian-io/@steempytutorials/part-5-post-an-article-directly-to-the-steem-blockchain-and-automatically-buy-upvotes-from-upvote-bots","https://steemit.com/utopian-io/@steempytutorials/part-7-how-to-schedule-posts-and-manually-upvote-posts-for-a-variable-voting-weight-with-steem-python","https://steemit.com/utopian-io/@steempytutorials/part-10-use-urls-to-retrieve-post-data-and-construct-a-dynamic-post-with-steem-python","https://steemit.com/utopian-io/@steempytutorials/how-to-calculate-a-post-s-total-rewards-using-steem-python","https://steemit.com/utopian-io/@steempytutorials/part-12-how-to-estimate-curation-rewards","https://steemit.com/utopian-io/@steempytutorials/how-to-estimate-all-rewards-in-last-n-days-using-steem-python","https://steemit.com/utopian-io/@steempytutorials/part-11-how-to-build-a-list-of-transfers-and-broadcast-these-in-one-transaction-with-steem-python","https://steemit.com/utopian-io/@steempytutorials/part-13-upvote-posts-in-batches-based-on-current-voting-power-with-steem-python","https://steemit.com/utopian-io/@steempytutorials/part-15-how-to-check-if-an-account-is-following-back-and-retrieve-mutual-followers-following-between-two-accounts","https://steemit.com/utopian-io/@steempytutorials/part-16-how-to-analyse-a-user-s-vote-history-in-a-specific-time-period-using-steem-python","https://steemit.com/utopian-io/@steempytutorials/part-18-how-to-analyse-an-account-s-resteemers"],"app":"steemit/0.1","format":"markdown"}
created2018-06-23 01:43:03
last_update2018-06-23 01:43:03
depth0
children3
last_payout2018-06-30 01:43:03
cashout_time1969-12-31 23:59:59
total_payout_value28.809 HBD
curator_payout_value8.660 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length11,634
author_reputation31,094,047,689,691
root_title"Part 24: An In Dept Look At Steem Operation Types Part I"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id61,846,309
net_rshares18,906,063,551,397
author_curate_reward""
vote details (29)
@angelhayden ·
Thank you for your very good tutorial !
properties (22)
authorangelhayden
permlinkre-steempytutorials-part-24-an-in-dept-look-at-steem-operation-types-part-i-20180628t191028056z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-06-28 19:10:30
last_update2018-06-28 19:10:30
depth1
children0
last_payout2018-07-05 19:10:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length39
author_reputation93,883,594
root_title"Part 24: An In Dept Look At Steem Operation Types Part I"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id62,653,128
net_rshares0
@utopian-io ·
Hey @steempytutorials
**Thanks for contributing on Utopian**.
We’re already looking forward to your next contribution!

**Want to chat? Join us on Discord https://discord.gg/h52nFrV.**

<a href='https://v2.steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1'>Vote for Utopian Witness!</a>
properties (22)
authorutopian-io
permlinkre-part-24-an-in-dept-look-at-steem-operation-types-part-i-20180625t095008z
categoryutopian-io
json_metadata"{"app": "beem/0.19.29"}"
created2018-06-25 09:50:09
last_update2018-06-25 09:50:09
depth1
children0
last_payout2018-07-02 09:50:09
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length308
author_reputation152,955,367,999,756
root_title"Part 24: An In Dept Look At Steem Operation Types Part I"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id62,171,026
net_rshares0
@yokunjon ·
I thank you for your contribution. Here are my thoughts on your post;

* As this is an explanation of the documentation, it would be better to increase the density of the volume by adding several more substantial concepts and making the post longer. While doing that, please avoid filler content.

----
Your contribution has been evaluated according to [Utopian policies and guidelines](https://join.utopian.io/guidelines), as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, [click here](https://review.utopian.io/result/8/21214413).

---- 
Need help? Write a ticket on https://support.utopian.io/. 
Chat with us on [Discord](https://discord.gg/uTyJkNm). 
[[utopian-moderator]](https://join.utopian.io/)
πŸ‘  
properties (23)
authoryokunjon
permlinkre-steempytutorials-part-24-an-in-dept-look-at-steem-operation-types-part-i-20180625t082907970z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"links":["https://join.utopian.io/guidelines","https://review.utopian.io/result/8/21214413","https://support.utopian.io/","https://discord.gg/uTyJkNm","https://join.utopian.io/"],"app":"steemit/0.1"}
created2018-06-25 08:28:51
last_update2018-06-25 08:28:51
depth1
children0
last_payout2018-07-02 08:28:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length793
author_reputation19,266,807,595,513
root_title"Part 24: An In Dept Look At Steem Operation Types Part I"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id62,161,796
net_rshares146,238,266
author_curate_reward""
vote details (1)