This tutorial is a continuation on Part 0: How to install steem-python, the official STEEM library for Python. We will be setting up the CLI wallet for with our steem account for future use. After that we will upvote an article with a python script.
What Will I Learn?
- How to set up your Steempy wallet
- Change the default node
- Import your Steem account
- Set wallet defaults
- Upvote directly via the blockchain
- python 3.6
Update default node
By default the node which steempy is connected to is http://steemd.steemit.com, this node has now been depreciated and we will have to update it to make the wallet work again. We will be using the Steemviz node, but this can be replaced with any node to your liking. Adding multiple nodes for redundancy is also possible by separating the urls with a comma
steempy set nodes https://rpc.steemviz.com
import steem account
Now you can add your account, replace steempytutorials with your account name
steempy importaccount steempytutorials
Importing active key!
Please provide a password for the new wallet
Importing posting key!
Importing memo key!
You will be asked for your master password. After this you will have to set up a password to encrypt your wallet. This password is needed for any transaction made with the wallet.
You can verify all the imported keys
configure wallet defaults
You can then set up a the default account and upvote weight for any future transactions or upvotes.
steempy set default_account steempytutorials
steempy set default_vote_weight 100
Now verify all the settings with
Your wallet is now ready to be used.
Upvoting an article with python
We will upvote 2 excellent articles made by @amosbastian with the python script below. The permlink is how steem identifies articles and you can get it from the url of an article. Removing the beginning of the urls until
@. While we will be using 2 preset permlinks you can also use your own. The 100 in
steem.vote(permlink,100) indicates the weight of the upvote we will be giving out. You can also alter this to your liking.
from steem import Steem steem = Steem() permlink = '@amosbastian/how-to-create-a-simple-reddit-bot-using-praw-1-streaming-and-replying' try: steem.vote(permlink,100) print ("Succesfully upvoted!") except Exception as e: print (repr(e))
Save the code as main.py and run it. You will be asked for you wallet passphrase and after that it should upvote the article.
While this works, it is annoying to have to enter the passphrase every time. To prevent this you can set your passphrase as an environment variable with:
Now we will alter the code a bit to accommodate for this.
from steem import Steem import os steemPostingKey = os.environ.get('steemPostingKey') steem = Steem(wif=steemPostingKey) permlink = '@amosbastian/python-wrapper-for-the-fantasy-premier-league-api' try: steem.vote(permlink,100) print ("Succesfully upvoted!") except Exception as e: print (repr(e))
Try it again and it should upvote without asking for your passphrase, succes! You can verify this by going to the article or going over to steemd.com.
Posted on Utopian.io - Rewarding Open Source Contributors