Part 5: Post An Article Directly To The Steem Blockchain And Automatically Buy Upvotes From Upvote Bots

steem-python.png

This tutorial is part of a series where we explain different aspects of programming with steem-python. Links to the other tutorials can be found below. You will learn how steem-python can be used to post an article from file directly to the Steem blockchain as well as built and broadcast a transaction to purchase an upvote for the article posterd.


What will I learn

  • What submitting a post looks like in steem-python
  • Creating an unique permlink
  • How a transaction is built
  • How to broadcast a transaction

Requirements

  • Python 3.6
  • steem-python

Difficulty

  • Basic

Tutorial

Set up

Start by downloading both files from github. The post.txt is used to store the post we want to submit and the title and tags we would like to use. The first line is used for the title and the second line is for the tags, separated by a whitespace. The rest of the file is the body of the post.

#1 Title 'Test' Buy Upvote
#2 blog test steemdev
#3 
#4 Test buying upvote from minnowbooster #5

In scheduler.py you will have to set the author, the upvote bot you want to use and what amount in SBD you want to buy upvotes for.

author = 'sttest2'
upvote_bot = 'minnowbooster'
amount = 0.05


What does submitting a post look like?

Submitting a post with steem-python requires several variables. Most of them are optional. We will be using the title, body, author, permlink and self_vote.

def post(self,
             title,
             body,
             author,
             permlink=None,
             reply_identifier=None,
             json_metadata=None,
             comment_options=None,
             community=None,
             tags=None,
             beneficiaries=None,
             self_vote=False):

Calling the post function to submit the post then looks like:

steem.post(title, body, author, permlink, None, None, None, None, tags, None, True)

Permlink

The permlink is an unique identifier for each post, which is linked to the author of the post. Leaving this blank steem-python will automatically assign a permlink based on the title. However, the permlink is needed to buy an upvote, therefor a permlink needs be to created from the title. To make sure the permlink created is unique and valid all characters except for letters and numbers will be removed, as well as capitals. A random number and a timestamp will be added as well.

permlink_title = ''.join(e for e in title if e.isalnum()).lower()
permlink = "{}-%s%s".format(permlink_title) % (time.strftime("%Y%m%d%H%M%S"), random.randrange(0,9999,1))

How is a transaction built?

A transaction is built up by a sender, receiver, amount in SBD/STEEM and an optional memo in a dict. For sender the author will b used and the receiver will be the upvote_bot. SBD will be used and the memo will be full url to the article, including permlink and author.

transfers =[{
        'from': author,
        'to': upvote_bot,
        'amount': 'amount SBD',
        'memo': 'full url to post'
    }]

The full url to the post can be created with the permlink and author as follows:

'https://steemit.com/@{}/{}'.format(author, permlink)

The next code is then used to sign and broadcast the transaction

    tb = Transactionbuilter()
    operation = [operations.Transfer(**x) for x in transfers]
    tb.appendOps(operation)
    tb.appendSigner(author, 'active')
    tb.sign()
    tx = tb.broadcast()

Note: transfers is a list with transactions. Each transaction is put in a dict. This allows for multiple transactions to be broadcasted at once. Like for example if you wish to purchase multiple upvotes from several upvote bots.

Running the code

Now that you have configured the code to your own liking you can test it for yourself.

python scheduler.py
Submitted post
Buying vote succes

Screenshot 2018-01-16 17.09.40.png

Curriculum

Credits

This tutorial was written by @juliank in conjunction with @amosbastian


The code for this tutorial can be found on GitHub!



Posted on Utopian.io - Rewarding Open Source Contributors

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now