This tutorial will explain and show you how to submit a new comment to the Steem blockchain using the commit class found within the steem-python library.
Intro
The Steem python library has a built-in function to transmit transactions to the blockchain. We are using the post method found within the commit class in the the library. It should be noted that comments and post are both treated as a commit.post operation with the only difference being that a comment/reply has an additional parameter containing the parent post/comment. There are 11 parameters within the post method:
title - The title of the post. This is a required parameter but comments don’t have a title so the parameter is assigned an empty string value
body - The body of the post
author - The account that you are posting from
permlink - A unique adentifier for the
tags - Between 1 and 5 key words that defines the post
reply_idendifier - Identifier of the parent post(used for comments)
json_metadata - JSON meta objec that can be attached to the post
comment_options - JSON options object that can be attached to the post to specify additional options like ‘max_payouts’, ‘allow_votes’, etc.
community - Name of the community you are posting into
beneficiaries - A list of beneficiaries for posting reward distribution.
self_vote - Upvote the post as author right after posting
We will only be using the parameters titel, body, author, permlink and reply_identifier as they are all that is required for a basic comment operation. If you want to explore the other parameters further you can find more information HERE.
A comment made on a post is defined as a root comment. You can also comment on someone elses (or your own) comment, in which case the parent parameters would be that of the comment, and not the original post.
Steps
App setup - Library install and import. Connection to Steem node
Because this tutorial alters the blockchain we have to connect to the testnet. There is a demo account available for use, cdemo with private posting key 5JEZ1EiUjFKfsKP32b15Y7jybjvHQPhnvCYZ9BW62H1LDUnMvHz. You can also create your own demo account by following the instructions on the TESTNET site.
2. Variable input and format
The variables are captured via a simple string input and allocated as seen below. The wif variable is the private posting key of the user making the comment. This key is required to commit the post to the blockchain.
We join the two parent values and assign it to the reply_identifier parameter. We also use a random generator to create a new permlink for the post being created
#combining parent values to create reply identifier
reply_identifier='/'.join([parentAuthor,parentPermlink])#random generator to create post permlink
permlink=''.join(random.choices(string.digits,k=10))
The random generator is limited to 10 characters in this case but the permlink can be up to 256 bytes. If the permlink value is left empty then it auto creates a permlink based on the title of the post. The permlink is unique to the author only which means that multiple authors can have the same title for thier post.
3. Initialize steem class
We initialize the steem class by connecting to the specific testnet node. We also require the private posting key of the contributing author in order to commit the post which is also specified during this operation.
#connect node and private posting key
client=steem.Steem(nodes=['https://testnet.steem.vc'],keys=[wif])
4. Post submission and result
The last step is to transmit the post through to the blockchain. This is done with the post method within the commit class. All the defined parameters are submitted with the function. As stated earlier in the tutorial, there are quite a few parameters for this function but for a basic comment these 5 are all that’s required.
#commit post to blockchain
client.commit.post(title='',body=body,author=author,permlink=permlink,reply_identifier=reply_identifier)print("Comment created successfully")print(permlink)
A simple confirmation is printed on the screen if the comment is committed successfully. We also print the permlink for the comment on screen. This is purely for convenience to make it easier to retrieve the permlink if a new author or the same author would like to another comment on the one just made.
You can also check on the testportal for the comment or for a post to comment on. Alternatively you can create your own post to comment on following the 10_submit_post tutorial.
PY: Submit Comment Reply
How to submit a comment on a post to the Steem blockchain.
Full, runnable src of Submit Comment Reply can be downloaded as part of the PY tutorials repository.
This tutorial will explain and show you how to submit a new comment to the
Steem
blockchain using thecommit
class found within the steem-python library.Intro
The Steem python library has a built-in function to transmit transactions to the blockchain. We are using the
post
method found within thecommit
class in the the library. It should be noted that comments and post are both treated as acommit.post
operation with the only difference being that a comment/reply has an additional parameter containing theparent post/comment
. There are 11 parameters within thepost
method:We will only be using the parameters titel, body, author, permlink and reply_identifier as they are all that is required for a basic comment operation. If you want to explore the other parameters further you can find more information HERE.
A comment made on a post is defined as a
root comment
. You can also comment on someone elses (or your own) comment, in which case theparent
parameters would be that of the comment, and not the original post.Steps
1. App setup
In this tutorial we use 4 packages:
random
andstring
- used to create a random string used for thepermlink
steem
- steem-python library and interaction with Blockchainsteembase
- used to connect to the testnetWe import the libraries and connect to the
testnet
.Because this tutorial alters the blockchain we have to connect to the testnet. There is a demo account available for use,
cdemo
with private posting key5JEZ1EiUjFKfsKP32b15Y7jybjvHQPhnvCYZ9BW62H1LDUnMvHz
. You can also create your own demo account by following the instructions on the TESTNET site.2. Variable input and format
The variables are captured via a simple string input and allocated as seen below. The
wif
variable is the private posting key of the user making the comment. This key is required to commit the post to the blockchain.We join the two
parent
values and assign it to thereply_identifier
parameter. We also use a random generator to create a newpermlink
for the post being createdThe random generator is limited to 10 characters in this case but the permlink can be up to 256 bytes. If the permlink value is left empty then it auto creates a permlink based on the title of the post. The permlink is unique to the author only which means that multiple authors can have the same title for thier post.
3. Initialize steem class
We initialize the steem class by connecting to the specific
testnet
node. We also require theprivate posting key
of the contributing author in order to commit the post which is also specified during this operation.4. Post submission and result
The last step is to transmit the post through to the blockchain. This is done with the
post
method within thecommit
class. All the defined parameters are submitted with the function. As stated earlier in the tutorial, there are quite a few parameters for this function but for a basic comment these 5 are all that’s required.A simple confirmation is printed on the screen if the comment is committed successfully. We also print the
permlink
for the comment on screen. This is purely for convenience to make it easier to retrieve the permlink if a new author or the same author would like to another comment on the one just made.You can also check on the testportal for the comment or for a post to comment on. Alternatively you can create your own post to comment on following the
10_submit_post
tutorial.To Run the tutorial
cd tutorials/11_submit_comment_reply
pip install -r requirements.txt
python index.py