create account

Part 3: How to manage your wallet using steem-python - Automatically manage your accounts by amosbastian

View this thread on: hive.blogpeakd.comecency.com
· @amosbastian · (edited)
$31.27
Part 3: How to manage your wallet using steem-python - Automatically manage your accounts
<center>![steem-python.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1515886103/kmzfcpvtzuwhvqhgpyjp.png)</center>

This tutorial is part of a series, so make sure to read the other tutorials before starting this tutorial. Today we will learn how to automatically send the rewards from your other accounts (if you have them) to your main account using `steem-python`!

---

#### What will I learn?
- How to add multiple accounts to steempy
- How to claim rewards on all your accounts
- How to transfer these rewards to a main account

#### Requirements
- Python3.6
- steem-python

#### Difficulty
- Basic

---

### Tutorial
#### Adding accounts
First thing you want to do is add your account's active key and posting key (not relevant for this tutorial, but still). You can do this by typing

```
steempy addkey
```
Once you have typed this you will see the following
```
Private Key (wif) [Enter to quit]:
```
simply paste one of your keys and press enter until you have entered all of your keys. If you now type `steempy listaccounts` it should show all the accounts you have entered, for example for me it shows

<center>![listaccounts.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1516285199/wg7nqlbywnrq2qdpdswb.png)</center>

#### Claiming rewards
We already learned how to do this in the previous tutorial, so we will simply adapt the code so it works with multiple accounts. First of all we need to make a list with all our accounts and change the `claim_rewards()` function to take a username as argument. Once we have the list we can simply loop over it and call the `claim_rewards()` function in every iteration, like so

```
def claim_rewards(username):
    reward_SBD = steem.get_account(username)["reward_sbd_balance"]
    reward_SP  = steem.get_account(username)["reward_vesting_steem"]
    print(f"{username} current rewards: {reward_SBD} and {reward_SP} POWER")

    if Amount(reward_SBD).amount + Amount(reward_SP).amount == 0:
        return
    else:
        steem.claim_reward_balance(account=username)
    print(f"Claim rewards: {reward_SBD} and {reward_SP} POWER")

steem = Steem()
accounts = ["sttest1", "sttest2"]

for account in accounts:
    claim_rewards(account)
```

which gives the following output

```
sttest1 current rewards: 0.000 SBD and 0.000 STEEM POWER
sttest2 current rewards: 0.000 SBD and 0.000 STEEM POWER
```
Unfortunately I don't have any rewards on these test accounts, but trust me, it actually works!

#### Transferring SBD
We can now claim all the rewards on all of our accounts, so the only thing left is to actually send the rewarded SBD to our main account. So instead of selling it on the market like we did in the previous tutorial, we are going to make a function called `transfer_sbd()` that does this for us. To do this we can use the `transfer()` function like so

```
def transfer_sbd(username):
    sbd_balance = Amount(steem.get_account(username)["sbd_balance"]).amount
    if not sbd_balance > 0:
        return
    print(f"Transferring {sbd_balance} to {main_account} from {username}")
    steem.transfer(main_account, sbd_balance, "SBD", account=username)
    
main_account = "amosbastian"

for account in accounts:
    claim_rewards(account)
    transfer_sbd(account)
```
where we make sure that we actually have some SBD to transfer. If you don't do this you might possibly get an error saying that you are trying to transfer a negative amount, and we don't want this! Anyway, the above code will output something similar to this

```
sttest1 current rewards: 0.000 SBD and 0.000 STEEM POWER
Transferring 0.011 to amosbastian from sttest1
sttest2 current rewards: 0.000 SBD and 0.000 STEEM POWER
Transferring 0.051 to amosbastian from sttest2
```
Going to my wallet shows it worked fine!

<center>![transfer_example.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1516285423/eyoudj8spdgzllx1vnhd.png)</center>

If you want to schedule your program to run every day for example, you can use a `crontab` as we discussed in the first part of this tutorial series. Don't forget that if you want to do this you would have to add each account's passphrase to the crontab as an environment variable and then load this in your Python file!

---

**Congratulations!** You can now automatically claim all the rewards on all of your accounts, then send these rewards to your main account where you can decide what to do with it!

#### Curriculum
- [Part 1: How to manage your wallet using steem-python - Automatically claim rewards](https://utopian.io/utopian-io/@amosbastian/how-to-manage-your-wallet-using-steem-python-1-claiming-rewards-automatically)
- [Part 2: How to manage your wallet using steem-python - Automatically sell SBD on the market](https://utopian.io/utopian-io/@amosbastian/part-2-how-to-manage-your-wallet-using-steem-python-automatically-sell-sbd-on-the-market)
---

The code for this tutorial can be found on my [GitHub](https://github.com/amosbastian/utopian-tutorials/blob/master/wallet-manager/account_manager.py)!

<br /><hr/><em>Posted on <a href="https://utopian.io/utopian-io/@amosbastian/part-3-how-to-manage-your-wallet-using-steem-python-automatically-manage-your-accounts">Utopian.io -  Rewarding Open Source Contributors</a></em><hr/>
πŸ‘  , , , , , , , , , , ,
properties (23)
authoramosbastian
permlinkpart-3-how-to-manage-your-wallet-using-steem-python-automatically-manage-your-accounts
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":["amosbastian"],"links":["https://res.cloudinary.com/hpiynhbhq/image/upload/v1515886103/kmzfcpvtzuwhvqhgpyjp.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1516285199/wg7nqlbywnrq2qdpdswb.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1516285423/eyoudj8spdgzllx1vnhd.png","https://utopian.io/utopian-io/@amosbastian/how-to-manage-your-wallet-using-steem-python-1-claiming-rewards-automatically","https://utopian.io/utopian-io/@amosbastian/part-2-how-to-manage-your-wallet-using-steem-python-automatically-sell-sbd-on-the-market","https://github.com/amosbastian/utopian-tutorials/blob/master/wallet-manager/account_manager.py"],"image":["https://res.cloudinary.com/hpiynhbhq/image/upload/v1515886103/kmzfcpvtzuwhvqhgpyjp.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1516285199/wg7nqlbywnrq2qdpdswb.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1516285423/eyoudj8spdgzllx1vnhd.png"],"moderator":{"account":"shreyasgune","time":"2018-01-18T17:07:50.480Z","reviewed":true,"pending":false,"flagged":false}}
created2018-01-18 14:30:57
last_update2018-01-18 17:07:51
depth0
children6
last_payout2018-01-25 14:30:57
cashout_time1969-12-31 23:59:59
total_payout_value22.758 HBD
curator_payout_value8.511 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length5,252
author_reputation174,473,586,900,705
root_title"Part 3: How to manage your wallet using steem-python - Automatically manage your accounts"
beneficiaries
0.
accountutopian.pay
weight2,500
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id30,406,993
net_rshares4,683,081,842,482
author_curate_reward""
vote details (12)
@indrajeet ·
This is a great help to thr steemit peoplr , thank you so much dear friend😊😊
properties (22)
authorindrajeet
permlinkre-amosbastian-part-3-how-to-manage-your-wallet-using-steem-python-automatically-manage-your-accounts-20180118t143331370z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-01-18 14:33:33
last_update2018-01-18 14:33:33
depth1
children1
last_payout2018-01-25 14:33:33
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_length76
author_reputation939,300,018,217
root_title"Part 3: How to manage your wallet using steem-python - Automatically manage your accounts"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id30,407,538
net_rshares0
@amosbastian ·
No problem!
properties (22)
authoramosbastian
permlinkre-indrajeet-re-amosbastian-part-3-how-to-manage-your-wallet-using-steem-python-automatically-manage-your-accounts-20180118t155358214z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-01-18 15:53:57
last_update2018-01-18 15:53:57
depth2
children0
last_payout2018-01-25 15:53: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_length11
author_reputation174,473,586,900,705
root_title"Part 3: How to manage your wallet using steem-python - Automatically manage your accounts"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id30,424,063
net_rshares0
@shreyasgune ·
$0.98
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)
authorshreyasgune
permlinkre-amosbastian-part-3-how-to-manage-your-wallet-using-steem-python-automatically-manage-your-accounts-20180118t170758710z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"}
created2018-01-18 17:08:00
last_update2018-01-18 17:08:00
depth1
children1
last_payout2018-01-25 17:08:00
cashout_time1969-12-31 23:59:59
total_payout_value0.976 HBD
curator_payout_value0.004 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length172
author_reputation4,924,803,411,962
root_title"Part 3: How to manage your wallet using steem-python - Automatically manage your accounts"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id30,438,149
net_rshares119,091,589,302
author_curate_reward""
vote details (2)
@amosbastian ·
Thanks!
properties (22)
authoramosbastian
permlinkre-shreyasgune-re-amosbastian-part-3-how-to-manage-your-wallet-using-steem-python-automatically-manage-your-accounts-20180118t173541872z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-01-18 17:35:42
last_update2018-01-18 17:35:42
depth2
children0
last_payout2018-01-25 17:35:42
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_length7
author_reputation174,473,586,900,705
root_title"Part 3: How to manage your wallet using steem-python - Automatically manage your accounts"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id30,443,554
net_rshares0
@steemitboard ·
Congratulations @amosbastian! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

[![](https://steemitimages.com/70x80/http://steemitboard.com/notifications/posts.png)](http://steemitboard.com/@amosbastian) Award for the number of posts published
[![](https://steemitimages.com/70x80/http://steemitboard.com/notifications/votes.png)](http://steemitboard.com/@amosbastian) Award for the number of upvotes
[![](https://steemitimages.com/70x80/http://steemitboard.com/notifications/comments.png)](http://steemitboard.com/@amosbastian) Award for the number of comments
[![](https://steemitimages.com/70x80/http://steemitboard.com/notifications/payout.png)](http://steemitboard.com/@amosbastian) Award for the total payout received
[![](https://steemitimages.com/70x80/http://steemitboard.com/notifications/voted.png)](http://steemitboard.com/@amosbastian) Award for the number of upvotes received
[![](https://steemitimages.com/70x80/http://steemitboard.com/notifications/post4day.png)](http://steemitboard.com/@amosbastian) You published 4 posts in one day
[![](https://steemitimages.com/70x80/http://steemitboard.com/notifications/postallweek.png)](http://steemitboard.com/@amosbastian) You published a post every day of the week

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click [here](https://steemit.com/@steemitboard)

If you no longer want to receive notifications, reply to this comment with the word `STOP`

> By upvoting this notification, you can help all Steemit users. Learn how [here](https://steemit.com/steemitboard/@steemitboard/http-i-cubeupload-com-7ciqeo-png)!
properties (22)
authorsteemitboard
permlinksteemitboard-notify-amosbastian-20180118t184311000z
categoryutopian-io
json_metadata{"image":["https://steemitboard.com/img/notifications.png"]}
created2018-01-18 18:43:12
last_update2018-01-18 18:43:12
depth1
children0
last_payout2018-01-25 18:43:12
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,681
author_reputation38,975,615,169,260
root_title"Part 3: How to manage your wallet using steem-python - Automatically manage your accounts"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id30,456,250
net_rshares0
@utopian-io ·
$0.02
### Hey @amosbastian 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 (23)
authorutopian-io
permlinkre-amosbastian-part-3-how-to-manage-your-wallet-using-steem-python-automatically-manage-your-accounts-20180119t191039555z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"}
created2018-01-19 19:10:39
last_update2018-01-19 19:10:39
depth1
children0
last_payout2018-01-26 19:10:39
cashout_time1969-12-31 23:59:59
total_payout_value0.016 HBD
curator_payout_value0.005 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,509
author_reputation152,955,367,999,756
root_title"Part 3: How to manage your wallet using steem-python - Automatically manage your accounts"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id30,690,358
net_rshares2,603,471,960
author_curate_reward""
vote details (1)