Hive Developer logo

Hive Developer Portal

JS: Get Account Comments

How to retrieve account comments from the Hive blockchain.

Full, runnable src of Get Account Comments can be downloaded as part of: tutorials/javascript (or download just this tutorial:

This tutorial will show how to fetch comments made by a specific account (in this case @hiveio) by demonstrating how to use the bridge.get_account_posts api function call. We will also demonstrate the most commonly used fields from the response object as well as how to parse the body of each comment.


We are using the bridge.get_account_posts function with dhive that returns the current state of the network as well as additional content. Each content body is written in markdown and could be submitted to the blockchain by many different applications built on top of Hive. For that reason we are using the remarkable npm package to parse markdown in a readable format.

Also see:


  1. App setup Configuration of dhive to use the proper connection and network.
  2. Query Query the path which we want to extract from Hive blockchain state.
  3. Formatting Formatting the JSON object to be viewed in a simple user interface.

1. App setup

Below we have dhive pointing to the main network with the proper chainId, addressPrefix and connection server. There is a public/app.js file which holds the Javascript segment of this tutorial. In the first few lines we define and configure library and packages.

const dhive = require('@hiveio/dhive');
let opts = {};
//connect to production server
opts.addressPrefix = 'STM';
opts.chainId =
//connect to server which is connected to the network/production
const client = new dhive.Client('');

const Remarkable = require('remarkable');
const md = new Remarkable({ html: true, linkify: true });

remarkable is assigned to the variable md with linkify and html options, allowing us to parse markdown links and html properly.

2. Query

Next, we have the main function which runs when the page is loaded.

// fetching comments made by author
const author = prompt('Account?', 'hiveio');'get_account_posts', {sort: 'comments', account: author, limit: 100})
    // work with state object

query is the path from where want to extract Hive blockchain state. In our example we are querying comments from the @hiveio account. The result will be the current state object with various information as well as the content property holding the content of the query.

The following is an example of the returned object:

      "title":"RE: 12th update of 2021 on BlockTrades work on Hive software",
      "body":"Yes, I think the above is quite probable.",
      "pending_payout_value":"0.021 HBD",
      "author_payout_value":"0.000 HBD",
      "curator_payout_value":"0.000 HBD",
      "promoted":"0.000 HBD",
      "max_accepted_payout":"1000000.000 HBD",

3. Formatting

Next we will format the above object properly to view in a simple user interface. From the above object, we are only interested in the content object which holds the data we require.

if (
        Object.keys(result).length === 0 &&
        result.constructor === Object
) {
    var comments = [];
    Object.keys(result.content).forEach(key => {
        const comment = result[key];
        const parent_author = comment.parent_author;
        const parent_permlink = comment.parent_permlink;
        const created = new Date(comment.created).toDateString();
        const body = md.render(comment.body);
        const totalVotes = comment.stats.total_votes;
            `<div class="list-group-item list-group-item-action flex-column align-items-start">\
            <div class="d-flex w-100 justify-content-between">\
              <h6 class="mb-1">@${}</h6>\
              <small class="text-muted">${created}</small>\
            <p class="mb-1">${body}</p>\
            <small class="text-muted">&#9650; ${totalVotes}, Replied to: @${parent_author}/${parent_permlink}</small>\
    document.getElementById('author').innerHTML = author;
    document.getElementById('comments').style.display = 'block';
    document.getElementById('comments').innerHTML = comments.join('');

We first check if result is not an empty object. We then iterate through each object in result and extract:

We format created date and time, parse body markdown and get totalVotes on that comment. Each line is then pushed and displayed separately.

Try it

Click the play button below:

To Run the tutorial

  1. git clone
  2. cd devportal/tutorials/javascript/09_get_account_comments
  3. npm i
  4. npm run dev-server or npm run start
  5. After a few moments, the server should be running at http://localhost:3000/