Made with postermywall
Good day fam,Today I tried interacting with one of Hive Engine's Js libraries, and it was really a nice experience. Since I joined Hive, I have planned on being a Hive developer one day, and this is my first step toward that goal. I tried turning my boring day into an interactive experience through interacting with the Hive's API with the Dhive library, and the experience was awesome.
If you are a backend developer or have interacted with APIs before, you know how cool they are. In my first attempt, I tried quering all users with a location of Ghana in their profile using the find_accounts method, but it seemed to be taking a lot of time due to the slow network here, and probably the idea used was not an optimal one.
My next attempt was using the getDiscussions method. There are so many things I could do with the getdiscussion. In this post, I will be discussing how you can use the getdiscussions_by_comments method to query users recent comments on the Hive chain.
In the first place, let's open our terminal and then initialize our project. Because I am using Nodejs, I initialize my project through the npm init comment.
After initializing, let's create a comments.js file, and this is where I will be writing the codes.
Now, the next step is about installing the necessary npm packages. For now, I will be using the @hiveio/dhive
library, so let's install it through npm install @hiveio/dhive
After successfully installing the dhive package, let's now open VS Code to write the script.
The first thing in our editor is to import dhive into comments.js before we would be able to use it. After importing, we can now create the clients we want to interact with. With Hive, there are different API endpoints to choose from. In my case, I added about 4 of them, which can be seen in the screenshot below. They are all ways we can interact with the hive chain.
Now, everything is set, let's now access the Hive engine database to get all the comments of an author. This is implemented, as seen in the screenshot below.
In the code above, I tried getting the comments of a Hive user through the getdiscussions_by_comments endpoint. There are about four parameters we can provide here. In my case, I provided two parameters: the start_author and limit parameters. This will help me get the comments of a user based on the limit provided.
Voila! We have our results on the console. This was my first impression of the dHive library, and I will be doing a lot of cool stuff with it. I hope you enjoyed it. I will be playing with the APIs a lot, and I can't wait to share more with you.
All screenshots used in this post are from my Laptop
I hope you found this useful. I am Abdul-Salam Issahaku, from Ghana. I am a student web developer and a blockchain enthusiast. I blog about technology, life and investments. You can follow me to be part of my Hive family. Thank you for your time.