Image: @steemitblog
Having recently started coding Steemit-related software, I have found the guidance to be somewhat wanting and my attempts to communicate with the team directly have so far been a failure[1]. So I have decided to try and document what I have ended up discovering to help others who find themselves in the same boat.
Granted, a lot of it has already been documented to some degree of others, to which the sources below are evidence. However, I have decided to document it anyways in order to make it easy for others to avoid the same pitfalls I have experienced. I am not making any claim to being an expert as I am still learning this technology - but hopefully what I have learned would be useful to others.
With that, let us begin.
Installation of steem-python
All you have to do is more or less is follow @emrebeyler's well-worded advice[1]. Personally, I use Python 3 so I just ran:
sudo pip3 install steem
which installed the actual module for me.
Signing into the Steemit backend
Here is a sequence of commands that would sign you into the backend:
python3
Python 3.6.5 (default, Apr 1 2018, 05:46:30)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from steem import *
>>> s_signed_in = steem.Steem(keys=['',''])
>>>
The key specified vary depending on what it is you intend to do. If you intend to do just look something up you actually don't need to provide any keys at all and don't need to sign in at all either as all the blockchain transactional data is open.
The following is how you get a STEEM handle without signing in:
>>> s_unsigned = steem.Steem()
Note: steem.Steem.steemd
instance does have a login
method (source code: steemd.py). I am not sure if it works but couldn't get to work it for me. So I would suggest to use the syntax above to sign in with the private key providing the necessary privileges. Please see the following for detailed descriptions of how to obtain your private keys as well as the access they provide[5].
Performing some basic operations
Let us now use some of the steem.Steemd
instances to perform some basic operations on the actual blockchain.
Let us say we want to look up basic info on a user.
The following call:
>>> s_unsigned.steemd.get_account("borepstein")
returns the following:
{'id': 128324, 'name': 'borepstein', 'owner': {'weight_threshold': 1, 'account_auths': [], 'key_auths': [['STM8AgbHeRF8ppc56ySqNa5kyae7KmYXCUjJdNFUJ6pHzBNban2YL', 1]]}, 'active': {'weight_threshold': 1, 'account_auths': [], 'key_auths': [['STM6DhahfUAiEZU3gQSntpSJ6B6zaLUnmNeBXG9ey5Ct8BZByDxKn', 1]]}, 'posting': {'weight_threshold': 1, 'account_auths': [['bottracker.app', 1], ['busy.app', 1], ['dtube.app', 1], ['smartsteem', 1], ['steemgigs.app', 1]], 'key_auths': [['', 1]]}, 'memo_key': '', 'json_metadata': '{"profile":{"profile_image":"
, 'proxy': '', 'last_owner_update': '1970-01-01T00:00:00', 'last_account_update': '2018-07-09T17:02:54', 'created': '2017-01-22T17:51:33', 'mined': False, 'recovery_account': 'steem', 'last_account_recovery': '1970-01-01T00:00:00', 'reset_account': 'null', 'comment_count': 0, 'lifetime_vote_count': 0, 'post_count': 3817, 'can_vote': True, 'voting_power': 2480, 'last_vote_time': '2018-07-17T23:56:48', 'balance': '17.680 STEEM', 'savings_balance': '0.000 STEEM', 'sbd_balance': '3.301 SBD', 'sbd_seconds': '14011479006', 'sbd_seconds_last_update': '2018-07-17T23:53:54', 'sbd_last_interest_payment': '2018-06-18T16:26:00', 'savings_sbd_balance': '0.000 SBD', 'savings_sbd_seconds': '0', 'savings_sbd_seconds_last_update': '2017-05-02T10:53:15', 'savings_sbd_last_interest_payment': '2017-05-02T10:53:15', 'savings_withdraw_requests': 0, 'reward_sbd_balance': '0.000 SBD', 'reward_steem_balance': '0.000 STEEM', 'reward_vesting_balance': '0.000000 VESTS', 'reward_vesting_steem': '0.000 STEEM', 'vesting_shares': '4828994.047796 VESTS', 'delegated_vesting_shares': '1643528.158619 VESTS', 'received_vesting_shares': '0.000000 VESTS', 'vesting_withdraw_rate': '479400.650168 VESTS', 'next_vesting_withdrawal': '2018-07-22T19:42:18', 'withdrawn': '3355804551176', 'to_withdraw': '6232208452191', 'withdraw_routes': 0, 'curation_rewards': 181072, 'posting_rewards': 2257212, 'proxied_vsf_votes': [0, 0, 0, 0], 'witnesses_voted_for': 6, 'last_post': '2018-07-17T23:52:30', 'last_root_post': '2018-07-17T23:52:30', 'average_bandwidth': '190507170537', 'lifetime_bandwidth': '8694540000000', 'last_bandwidth_update': '2018-07-18T00:34:36', 'average_market_bandwidth': '251929050643', 'lifetime_market_bandwidth': '1961880000000', 'last_market_bandwidth_update': '2018-07-17T21:58:15', 'vesting_balance': '0.000 STEEM', 'reputation': '30033882099703', 'transfer_history': [], 'market_history': [], 'post_history': [], 'vote_history': [], 'other_history': [], 'witness_votes': ['arcange', 'ausbitbank', 'dragosroua', 'krnel', 'therealwolf', 'yabapmatt'], 'tags_usage': [], 'guest_bloggers': []}
The following would return a brief summary of the last 10 entries of that user's blog:
>>> s_unsigned.steemd.get_blog_entries(account="borepstein", entry_id=-1, limit=5)
The summary produced will look like this:
[{'author': 'borepstein', 'permlink': 'markdown-quick-reference', 'blog': 'borepstein', 'reblog_on': '1970-01-01T00:00:00', 'entry_id': 11155}, {'author': 'blocktrades', 'permlink': 'blocktrades-introduces-crypto-affiliates-program-for-entrepreneurs', 'blog': 'borepstein', 'reblog_on': '2018-07-17T23:26:21', 'entry_id': 11154}, {'author': 'borepstein', 'permlink': 'avoiding-the-toxicity-of-blue-pill-therapy', 'blog': 'borepstein', 'reblog_on': '1970-01-01T00:00:00', 'entry_id': 11153}, {'author': 'brumest', 'permlink': 'the-staring-game', 'blog': 'borepstein', 'reblog_on': '2018-07-17T19:45:12', 'entry_id': 11152}, {'author': 'gavvet', 'permlink': 'how-many-of-you-would-like-to-see-evergreen-content-on-steemit', 'blog': 'borepstein', 'reblog_on': '2018-07-17T19:44:54', 'entry_id': 11151}]
Now this is somewhat convoluted but gives you an idea of how the data is formatted.
Let's see we want to look at the entry #3 in this list and get the entirety of it. Here's how we can do that:
>>> e = s_unsigned.steemd.get_blog_entries(account="borepstein", entry_id=-1, limit=5)[2]
>>> s_unsigned.get_blog(account="borepstein", entry_id=e["entry_id"], limit=1)[1]
The output is going to looks like the following:
{'comment': {'id': 56888286, 'author': 'borepstein', 'permlink': 'avoiding-the-toxicity-of-blue-pill-therapy', 'category': 'psychiatry', 'parent_author': '', 'parent_permlink': 'psychiatry', 'title': 'Avoiding the Toxicity of Blue Pill Therapy', 'body': , 'json_metadata': , 'last_update': '2018-07-17T22:19:18', 'created': '2018-07-17T22:19:18', 'active': '2018-07-17T23:31:09', 'last_payout': '1970-01-01T00:00:00', 'depth': 0, 'children': 2, 'net_rshares': '48873065698', 'abs_rshares': '48873065698', 'vote_rshares': '48873065698', 'children_abs_rshares': '65404592384', 'cashout_time': '2018-07-24T22:19:18', 'max_cashout_time': '1969-12-31T23:59:59', 'total_vote_weight': 224289, 'reward_weight': 10000, 'total_payout_value': '0.000 SBD', 'curator_payout_value': '0.000 SBD', 'author_rewards': 0, 'net_votes': 5, 'root_author': 'borepstein', 'root_permlink': 'avoiding-the-toxicity-of-blue-pill-therapy', 'max_accepted_payout': '1000000.000 SBD', 'percent_steem_dollars': 10000, 'allow_replies': True, 'allow_votes': True, 'allow_curation_rewards': True, 'beneficiaries': []}, 'blog': 'borepstein', 'reblog_on': '1970-01-01T00:00:00', 'entry_id': 11153}
Now let us attempt to use something that involved modifying the blockchain. For example. let us create a new user. Syntax like the following should do the trick:
s_signed_in.commit.create_account(account_name="test1", json_meta=None, password="letmein", owner_key=None, active_key=None, posting_key=None, memo_key=None, additional_owner_keys=[], additional_active_keys=[], additional_posting_keys=[], additional_owner_accounts=[], additional_active_accounts=[], additional_posting_accounts=[], store_keys=True, store_owner_key=True, delegation_fee_steem='1 STEEM', creator="borepstein")
The creation, or delegation, fee necessary seems to change from day to day and from minute to minute - I have still not figured out how that part works.
This is it for now. To be continued, hopefully...
Sources
Getting in touch with the Steemit team
@borepstein, 26 June 2018Steem-Python for dummies #1
@emrebeyler, 22 November 2017steem-python for dummies #7 - Creating accounts
@emrebeyler, 9 December 2017Public and Private Keys - how they are used by Steem, making all of this possible? You can find answer here
@noisy, 15 June 2017