#
Comment-reply and Post operations
One of the complex operations supported by the Hive blockchain is the publishing of blog posts and replies (comments) to them. To simplify it, the Wax library provides specific helper operation factory classes: BlogPostOperation
and ReplyOperation
. Below, we provide snippets for creating blog posts and replies including scenarios where additional properties are defined. These scenarios internally involve an additional blockchain operation called comment_options_operation
.
#
Creating a blog post with custom JSON-metadata properties
Test it yourself: src/typescript/transaction/operations/comment/creating-article.ts
import { createHiveChain, BlogPostOperation } from '@hiveio/wax';
// Initialize hive chain interface
const chain = await createHiveChain();
// Initialize a transaction object
const tx = await chain.createTransaction();
/**
* Uses the push operation on the transaction and specifies an argument:
* The operation class new instance, which takes an object as the argument with the operation configuration.
*/
tx.pushOperation(new BlogPostOperation({
// Here you can pass the arguments to given class constructor
author: 'post-author',
permlink: 'post-title',
body: 'the-post-body',
title: 'The Post Title',
category: 'literature',
description: 'This is the description of the post inside BlogPostOperation',
alternativeAuthor: 'Ernest Hemingway',
beneficiaries: [{ account: 'conan-librarian', weight: 40 }]
}));
// Get a transaction object holding all operations and transaction TAPOS & expiration data, but transaction is **not signed yet**
console.log(tx.transaction);
#
Creating a Comment (Reply) with multiple JSON-metadata attributes
You can set multiple properties on one operation class instance, as shown in the example below.
Test it yourself: src/typescript/transaction/operations/comment/creating-reply.ts
import { createHiveChain, ReplyOperation } from '@hiveio/wax';
// Initialize hive chain interface
const chain = await createHiveChain();
// Initialize a transaction object
const tx = await chain.createTransaction();
// Use multiple explicit values
tx.pushOperation(new ReplyOperation({
// Here you can pass the arguments to given operation class constructor
// Here `parentAuthor` and `parentPermlink` arguments can't be skipped nor be empty.
// Also other required operation basic attributes (like `author`) must be explicitly specified.
parentAuthor: 'parent-author',
parentPermlink: 'parent-permlink',
author: 'reply-author',
permlink: 'reply-permlink',
body: 'the-reply-body',
description: 'This is the description of the post inside ReplyOperation',
tags: ['hive']
}));
// Get a transaction object holding all operations and transaction TAPOS & expiration data, but transaction is **not signed yet**
console.log(tx.transaction);