Coding DIY part 4: My First Impression of Hive's dHive Library

in #hive-1693212 years ago


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.


Sort:  

Congratulations @lifeof.abdul! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)

You received more than 3250 upvotes.
Your next target is to reach 3500 upvotes.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Check out our last posts:

Our Hive Power Delegations to the March PUM Winners
Feedback from the April Hive Power Up Day
Hive Power Up Month Challenge - March 2023 Winners List
The Hive Gamification Proposal

Thanks for your contribution to the STEMsocial community. Feel free to join us on discord to get to know the rest of us!

Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).

You may also include @stemsocial as a beneficiary of the rewards of this post to get a stronger support.