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:
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.
Firstly some information about my own environment:
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
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.
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")
Team South Africa banner designed by @bearone