So firstly I'd like to apologize to everyone who was following my tutorials that I made in the past. I've been super busy the past few months and I'm finally getting some direction in my career and life. Some things that have happened lately:
- I finally graduated University
- I'm almost done with my internship at a well established international company and will be starting as a junior software developer at the company next year
- I'm currently on holiday for the next month and decided to get back to posting on Steemit to keep me busy
Ok enough about be me, let's get started
This tutorial will be a light introduction to the steem-python library which you can use to develop your own programs on the steem blockchain. I've done a few of these in the past but decided to an updated version since I was getting a lot of comments regarding environmental errors and some of my own syntax errors.
What this tutorial will be covering:
- Setting up your environment and getting the library
- Retrieving information from the blockchain using the library
- Posting to the blockchain using the library
1. Setting up your environment and getting the library
Firstly some information about my own environment:
- Ubuntu 17.10
- Python 3.6.3
I won't be copying every step of the tutorial that I followed to get my environment set up so I'll rather just link it here . You can skip the virtual environment part if you want even though it is recommended if you're scared that you're going to fuck shit up.
Next we need to install the library which you can get by running the following command in the terminal:
~$ pip3 install steem
If you get an Command "python setup.py egg_info" failed with error code 1...
error while installing the steem library I would recommend looking at this thread since I got this error and managed to fix it using the answer in this following thread
Next we'll create a blank file where we'll be doing all the magic so head back to the terminal and create a blank Python file using your favorite text editor. I'll be using gedit for the sake of simplicity:
~$ gedit myFirstProgram.py
Add the following two lines at the top your blank file:
from steem import Steem
which is our import statement for the library we'll be using
and
steem = Steem()
which is our instance of the library we'll be using
2. Retrieving information from the blockchain using the library
To test that everything is working we can add the following line to our file created in step 1:
print(steem.get_account_count())
Save and close the file. We can now run our first little program by running the following command in the terminal ~$ python3 myFirstProgram.py
which will retrieve the amount of accounts currently on Steemit which at the time I created this was 505 922 which was around 280K back in June this year when I joined. Seeing some nice growth even though a ton of them are most likely just bots.
The documentation has some great things in there you can use to retrieve information from the blockchain. If you wanted to get all your account information from the blockchain you could add the following line of code to your file print(steem.get_account('yourAccountName'))
I'd recommend you check out the documentation for a full list stuff you can do with the library.
3. Posting to the blockchain using the library
In this little example I'll show you how to reply to a post on Steemit. In order to post to the blackchain we need to add our private posting key which we can find in our profile under "Permissions".
Edit the following line in your file steem = Steem()
and change it to steem = Steem(keys=["your-private-posting-key-here"])
Now we can use the library to post on our behalf so you can use the following line of code to reply to any post on steemit:
steem.post("some title", "some message", "your username", "", "Link to the post you are replying to")
Some notes:
- your username should be added without the '@' symbol
- The link to the post you're replying to has the following format "@author/link-of-the-post-or-reply"
And that's it for today. Please let me know if this was useful and if you'd like so see more of these as well as if there's any improvements I could make.
Team South Africa banner designed by @bearone
Great stuff! And congratulations on all your achievements!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Interesting stuff. With this library one could look at some profile and find the average posting time or some statistics like that?
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Yes definitely
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit