This example will broadcast a reply to the blockchain using the values provided. To create a post in ruby, we will use a Radiator::Transaction containing a comment operation, which is how all content is stored internally.
A reply is differentiated from a post by whether or not a parent_author exists. When there is no parent_author, then it’s a post, otherwise it’s a comment (like in this example).
First, set up your workstation using the steps provided in Getting Started. Then you can create and execute the script (or clone from this repository):
You can launch a local testnet, with port 8090 mapped locally to the docker container:
The response we get after broadcasting the transaction gives us the transaction id (3fef14c...), block number (22867626), and the transaction number of that block (13).
Error Handling
We’re checking the result for error in case the remote node has an issue to raise. Normally, it will be nil, but if it’s populated, output error.message and exit.
Submit Comment Reply
How to post a simple comment to Hive.
Full, runnable src of Submit Comment Reply can be downloaded as part of: tutorials/ruby (or download just this tutorial: devportal-master-tutorials-ruby-11_submit_comment_reply.zip).
Intro
This example will broadcast a reply to the blockchain using the values provided. To create a post in
ruby
, we will use aRadiator::Transaction
containing acomment
operation, which is how all content is stored internally.A reply is differentiated from a post by whether or not a
parent_author
exists. When there is noparent_author
, then it’s a post, otherwise it’s a comment (like in this example).Also see:
Script
submit_comment_reply.rb
You should change
wif
to the posting key that matches yourauthor
. This script will pass along the values as acomment
operation:author
- Account name of the author currently replying.permlink
- Value unique to the authorparent_author
- The name of the author of the being replied to, in the case of a reply like this example.parent_permlink
- The permlink of the content being replied to, in the case of a reply like this example.title
- Typically empty.body
- The actual content of the post.json_metadata
- JSON containing theparent_permlink
of the root post as a tags array.Final code:
To Run
First, set up your workstation using the steps provided in Getting Started. Then you can create and execute the script (or clone from this repository):
You can launch a local testnet, with port 8090 mapped locally to the docker container:
For details on running a local testnet, see: Setting Up a Testnet
Example Output
The response we get after broadcasting the transaction gives us the transaction id (
3fef14c...
), block number (22867626
), and the transaction number of that block (13
).Error Handling
We’re checking the result for
error
in case the remote node has an issue to raise. Normally, it will benil
, but if it’s populated, outputerror.message
and exit.