create account

Part 11: How To Build A List Of Transfers And Broadcast These In One Transaction With Steem-Python by steempytutorials

View this thread on: hive.blogpeakd.comecency.com
· @steempytutorials · (edited)
$38.57
Part 11: How To Build A List Of Transfers And Broadcast These In One Transaction With Steem-Python
<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 on [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). Where part 10 focused on constructing the post, this tutorial will post it to blockchain, upvote it for a variable amount and transfer SBD to each author in one transaction.

---

#### What will I learn

- How to build a list of transfers
- Broadcast a list of transfers in one transaction

#### Requirements

- Python3.6
- `steem-python`

#### Difficulty

- Basic

---

### Tutorial

#### Setup
Start by going over the previous tutorial if you have not done so. After this download the files from [Gitub](https://github.com/amosbastian/steempy-tutorials/tree/master/part_11). Again there are 2 files. A text file in which the urls and post meta data is stored and the python script itself. In this example a post containing winners from a photography contest is constructed from urls, to each winners entry. This post is then submitted to the blockchain, and upvoted for a variable weight. In addition prize money is payed out to all winners in one grouped transaction on the blockchain.

In order to submit the post additional data is required. This will be stored in `winners.txt` before the urls.

```
winners.txt

#1 account
#2 post title
#3 tags
#4 upvote weight
#5 memo for transaction
#6 total amount of SBD
#7-7+n urls
```

Run the script by with the filename as the first argument
`> python main.py winners.txt`
####  How to build a list of transactions
The Steem blockchain allows for transfers to be grouped together in one transaction. To make use of this, a list of each transfer has to be made. After which this list can be broadcasted at once. Each transfer consists of a sender `from`, receiver `to`, amount in `x.xxx SBD` or `x.xxx STEEM` and a `memo` which can contain a message.

```
transfers = []

for each winner:
  transfers.append(    {
          'from': account,
          'to': author,
          'amount': '{0:.3f} SBD'.format(amount),
          'memo': memo
      })
```


#### Broadcast a transaction
The next block of code takes the list of transfers and constructs a single transaction. This is then broadcasted to the blockchain. `no_broadcast=False` can be set to `True` in case of testing. This allows you to test if everything is correct before sending SBD/STEEM.


```
tb = TransactionBuilder(no_broadcast=False)
operation = [operations.Transfer(**x) for x in transfers]
tb.appendOps(operation)
tb.appendSigner(account, 'active')
tb.sign()
tx = tb.broadcast()
```

#### Submitting and upvoting the post
The part which submits the post to the blockchain and upvotes it for a variable upvote weight has been taken from a [previous tutorial](https://steemit.com/utopian-io/@steempytutorials/part-7-how-to-schedule-posts-and-manually-upvote-posts-for-a-variable-voting-weight-with-steem-python)

```
steem.post(title, body, account, permlink, None, None, None, None, tags, None, False)
steem.vote('@{}/{}'.format(account, permlink), upvote_weight, account)
```


#### Running the code
Running the code will now construct a post from urls and metadata. Submit it to the blockchain, upvote the post and transfer SBD to each winner. As can be seen in the photo below. The` transaction_id` for each SBD transfer is the same. Grouping transaction increases efficiency and reduces stress on the blockchain,.

![Screenshot 2018-01-22 18.30.54.png](https://steemitimages.com/DQmbQASz9jdD3kKii9tmL7fn5wzPpZaLYvT2dofmKyGmMqV/Screenshot%202018-01-22%2018.30.54.png)

To combine knowledge from the other tutorials. To schedule this post to be submitted at a certain time the following command can be used.

```
> echo 'python main.py winners.txt' | at 6:00 PM
```


#### Curriculum
- [Part 0: How To Install Steem-python, The Official Steem Library For Python](https://utopian.io/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://utopian.io/utopian-io/@steempytutorials/part-1-how-to-configure-the-steempy-cli-wallet-and-upvote-an-article-with-steem-python)
- [Part 2: How To Stream And Filter The Blockchain Using Steem-Python](https://utopian.io/utopian-io/@steempytutorials/part-2-how-to-stream-and-filter-the-blockchain-using-steem-python)
- [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://utopian.io/utopian-io/@steempytutorials/part-4-how-to-follow-a-voting-trail-using-steem-python)
- [Part 5: Post An Article Directly To The Steem Blockchain And Automatically Buy Upvotes From Upvote Bots](https://utopian.io/utopian-io/@steempytutorials/part-5-post-an-article-directly-to-the-steem-blockchain-and-automatically-buy-upvotes-from-upvote-bots)
- [Part 6: How To Automatically Reply To Mentions Using Steem-Python](https://utopian.io/utopian-io/@steempytutorials/part-6-how-to-automatically-reply-to-mentions-using-steem-python)
- [Part 7: How To Schedule Posts And Manually Upvote Posts For A Variable Voting Weight With Steem-Python](https://utopian.io/utopian-io/@steempytutorials/part-7-how-to-schedule-posts-and-manually-upvote-posts-for-a-variable-voting-weight-with-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)
- [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 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)

---

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

This tutorial was written by @juliank in conjunction with @amosbastian.


<br /><hr/><em>Posted on <a href="https://utopian.io/utopian-io/@steempytutorials/part-11-how-to-build-a-list-of-transfers-and-broadcast-these-in-one-transaction-with-steem-python">Utopian.io -  Rewarding Open Source Contributors</a></em><hr/>
👍  , , , , , , , , , , , , , , , , , , , , , , , , , ,
properties (23)
authorsteempytutorials
permlinkpart-11-how-to-build-a-list-of-transfers-and-broadcast-these-in-one-transaction-with-steem-python
categoryutopian-io
json_metadata{"community":"utopian","app":"utopian/1.0.0","format":"markdown","repository":{"id":84843862,"name":"steem-python","full_name":"steemit/steem-python","html_url":"https://github.com/steemit/steem-python","fork":false,"owner":{"login":"steemit"}},"pullRequests":[],"platform":"github","type":"tutorials","tags":["utopian-io","steemdev","programming","python","tutorial"],"users":["steempytutorials","amosbastian","juliank","amosbastian."],"links":["https://res.cloudinary.com/hpiynhbhq/image/upload/v1515886103/kmzfcpvtzuwhvqhgpyjp.png","https://steemit.com/utopian-io/@steempytutorials/part-10-use-urls-to-retrieve-post-data-and-construct-a-dynamic-post-with-steem-python","https://github.com/amosbastian/steempy-tutorials/tree/master/part_11","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://steemitimages.com/DQmbQASz9jdD3kKii9tmL7fn5wzPpZaLYvT2dofmKyGmMqV/Screenshot%202018-01-22%2018.30.54.png","https://utopian.io/utopian-io/@amosbastian/how-to-install-steem-python-the-official-steem-library-for-python","https://utopian.io/utopian-io/@steempytutorials/part-1-how-to-configure-the-steempy-cli-wallet-and-upvote-an-article-with-steem-python","https://utopian.io/utopian-io/@steempytutorials/part-2-how-to-stream-and-filter-the-blockchain-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://utopian.io/utopian-io/@steempytutorials/part-4-how-to-follow-a-voting-trail-using-steem-python","https://utopian.io/utopian-io/@steempytutorials/part-5-post-an-article-directly-to-the-steem-blockchain-and-automatically-buy-upvotes-from-upvote-bots","https://utopian.io/utopian-io/@steempytutorials/part-6-how-to-automatically-reply-to-mentions-using-steem-python","https://utopian.io/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-8-how-to-create-your-own-upvote-bot-using-steem-python","https://steemit.com/utopian-io/@steempytutorials/how-to-calculate-a-post-s-total-rewards-using-steem-python"],"image":["https://res.cloudinary.com/hpiynhbhq/image/upload/v1515886103/kmzfcpvtzuwhvqhgpyjp.png","https://steemitimages.com/DQmbQASz9jdD3kKii9tmL7fn5wzPpZaLYvT2dofmKyGmMqV/Screenshot%202018-01-22%2018.30.54.png"],"moderator":{"account":"emrebeyler","time":"2018-01-22T20:01:36.808Z","reviewed":true,"pending":false,"flagged":false}}
created2018-01-22 18:09:27
last_update2018-01-22 20:01:36
depth0
children7
last_payout2018-01-29 18:09:27
cashout_time1969-12-31 23:59:59
total_payout_value30.248 HBD
curator_payout_value8.320 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length6,873
author_reputation31,094,047,689,691
root_title"Part 11: How To Build A List Of Transfers And Broadcast These In One Transaction With Steem-Python"
beneficiaries
0.
accountutopian.pay
weight2,500
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id31,442,923
net_rshares4,328,258,232,345
author_curate_reward""
vote details (27)
@apnigrich ·
Very interesting.
It would be good to learn all this.
properties (22)
authorapnigrich
permlinkre-steempytutorials-part-11-how-to-build-a-list-of-transfers-and-broadcast-these-in-one-transaction-with-steem-python-20180123t063150100z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-01-23 06:31:51
last_update2018-01-23 06:31:51
depth1
children0
last_payout2018-01-30 06:31: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_length53
author_reputation391,756,840,927,251
root_title"Part 11: How To Build A List Of Transfers And Broadcast These In One Transaction With Steem-Python"
beneficiaries
0.
accountminnowsupport
weight500
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id31,574,166
net_rshares0
@emrebeyler ·
$0.74
Thank you for the contribution. It has been approved.

You can contact us on [Discord](https://discord.gg/uTyJkNm).
**[[utopian-moderator]](https://utopian.io/moderators)**
👍  , ,
properties (23)
authoremrebeyler
permlinkre-steempytutorials-part-11-how-to-build-a-list-of-transfers-and-broadcast-these-in-one-transaction-with-steem-python-20180122t200146487z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"}
created2018-01-22 20:01:51
last_update2018-01-22 20:01:51
depth1
children1
last_payout2018-01-29 20:01:51
cashout_time1969-12-31 23:59:59
total_payout_value0.570 HBD
curator_payout_value0.168 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length172
author_reputation448,535,049,068,622
root_title"Part 11: How To Build A List Of Transfers And Broadcast These In One Transaction With Steem-Python"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id31,465,572
net_rshares66,536,767,344
author_curate_reward""
vote details (3)
@juliank ·
Mucho gracias!
properties (22)
authorjuliank
permlinkre-emrebeyler-re-steempytutorials-part-11-how-to-build-a-list-of-transfers-and-broadcast-these-in-one-transaction-with-steem-python-20180123t043422050z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-01-23 04:34:21
last_update2018-01-23 04:34:21
depth2
children0
last_payout2018-01-30 04:34:21
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_length14
author_reputation117,823,071,447,502
root_title"Part 11: How To Build A List Of Transfers And Broadcast These In One Transaction With Steem-Python"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id31,554,739
net_rshares0
@muselew ·
Good tutorial!
properties (22)
authormuselew
permlinkre-steempytutorials-part-11-how-to-build-a-list-of-transfers-and-broadcast-these-in-one-transaction-with-steem-python-20180122t210557944z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-01-22 21:05:57
last_update2018-01-22 21:05:57
depth1
children0
last_payout2018-01-29 21:05:57
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_length14
author_reputation2,392,465,159
root_title"Part 11: How To Build A List Of Transfers And Broadcast These In One Transaction With Steem-Python"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id31,477,700
net_rshares0
@setianyareza ·
$0.02
very informative and educative post, I will try this tutorial
👍  
properties (23)
authorsetianyareza
permlinkre-steempytutorials-part-11-how-to-build-a-list-of-transfers-and-broadcast-these-in-one-transaction-with-steem-python-20180122t181412556z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-01-22 18:14:15
last_update2018-01-22 18:14:15
depth1
children1
last_payout2018-01-29 18:14:15
cashout_time1969-12-31 23:59:59
total_payout_value0.018 HBD
curator_payout_value0.006 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length61
author_reputation11,771,963,526
root_title"Part 11: How To Build A List Of Transfers And Broadcast These In One Transaction With Steem-Python"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id31,443,860
net_rshares2,472,254,616
author_curate_reward""
vote details (1)
@steempytutorials ·
Have fun! If you have any questions feel free to ask
properties (22)
authorsteempytutorials
permlinkre-setianyareza-re-steempytutorials-part-11-how-to-build-a-list-of-transfers-and-broadcast-these-in-one-transaction-with-steem-python-20180122t185635363z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-01-22 18:56:36
last_update2018-01-22 18:56:36
depth2
children0
last_payout2018-01-29 18:56:36
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_length52
author_reputation31,094,047,689,691
root_title"Part 11: How To Build A List Of Transfers And Broadcast These In One Transaction With Steem-Python"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id31,452,281
net_rshares0
@utopian-io ·
### Hey @steempytutorials 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!
- Seems like you contribute quite often. AMAZING!
#### Suggestions
- Contribute more often to get higher and higher rewards. I wish to see you often!
- Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!
#### Get Noticed!
- Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!
#### Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. <a href="https://discord.gg/zTrEMqB">Participate on Discord</a>. Lets GROW TOGETHER!
- <a href="https://v2.steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1">Vote for my Witness With SteemConnect</a>
- <a href="https://v2.steemconnect.com/sign/account-witness-proxy?proxy=utopian-io&approve=1">Proxy vote to Utopian Witness with SteemConnect</a>
- Or vote/proxy on <a href="https://steemit.com/~witnesses">Steemit Witnesses</a>

[![mooncryption-utopian-witness-gif](https://steemitimages.com/DQmYPUuQRptAqNBCQRwQjKWAqWU3zJkL3RXVUtEKVury8up/mooncryption-s-utopian-io-witness-gif.gif)](https://steemit.com/~witnesses)

**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**
properties (22)
authorutopian-io
permlinkre-steempytutorials-part-11-how-to-build-a-list-of-transfers-and-broadcast-these-in-one-transaction-with-steem-python-20180123t143803732z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"}
created2018-01-23 14:38:03
last_update2018-01-23 14:38:03
depth1
children0
last_payout2018-01-30 14:38:03
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_length1,514
author_reputation152,955,367,999,756
root_title"Part 11: How To Build A List Of Transfers And Broadcast These In One Transaction With Steem-Python"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id31,663,768
net_rshares0