This tutorial will show how to fetch comments made by a specific account (in this case @steemitblog) by demonstrating how to use the get_state 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.
Intro
We are using the get_state function with dsteem 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 Steem. For that reason we are using the remarkable npm package to parse markdown in a readable format.
Steps
App setup Configuration of dsteem to use the proper connection and network.
Query Query the path which we want to extract from Steem blockchain state.
Formatting Formatting the JSON object to be viewed in a simple user interface.
1. App setup
Below we have dsteem 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.
constdsteem=require('dsteem');letopts={};//connect to production serveropts.addressPrefix='STM';opts.chainId='0000000000000000000000000000000000000000000000000000000000000000';//connect to server which is connected to the network/productionconstclient=newdsteem.Client('https://api.steemit.com');constRemarkable=require('remarkable');constmd=newRemarkable({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.
// query string, fetching comments made by @steemitblog accountconstquery='/@steemitblog/comments';client.database.call('get_state',[query]).then(result=>{// work with state object});
query is the path from where want to extract Steem blockchain state. In our example we are querying comments from the @steemitblog 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:
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.
JS: Get Account Comments
By the end of this tutorial you should know how to retrieve account comments from the steem blockchain
Full, runnable src of Get Account Comments can be downloaded as part of the JS tutorials repository.
This tutorial will show how to fetch comments made by a specific account (in this case
@steemitblog) by demonstrating how to use theget_stateapi 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.Intro
We are using the
get_statefunction withdsteemthat 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 Steem. For that reason we are using theremarkablenpm package to parse markdown in a readable format.Steps
dsteemto use the proper connection and network.1. App setup
Below we have
dsteempointing to the main network with the proper chainId, addressPrefix and connection server. There is apublic/app.jsfile which holds the Javascript segment of this tutorial. In the first few lines we define and configure library and packages.remarkableis assigned to the variablemdwith linkify and html options, allowing us to parse markdown links and html properly.2. Query
Next, we have the
mainfunction which runs when the page is loaded.queryis the path from where want to extract Steem blockchain state. In our example we are queryingcommentsfrom the@steemitblogaccount. The result will be the current state object with various information as well as thecontentproperty holding the content of the query.The following is an example of the returned object:
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
contentobject which holds the data we require.We first check if
contentis not an empty object. We then iterate through each object incontentand extract:parent_authorparent_permlink@steemitblogaccount is replying toWe format
createddate and time, parsebodymarkdown and getnet_voteson that comment. Each line is then pushed and displayed separately.To Run the tutorial
cd tutorials/09_get_account_commentsnpm inpm run dev-serverornpm run start