How to use @dhive/dhive library?
Why to use dhive library?
- it robust hive client library written in javascript
- It runs in both node.js and the browser
- Auto switching api nodes
- Easy access to different APIs
How to install it in your node.js app?
- You can view npm package of
dhive
using following link. - https://www.npmjs.com/package/@hiveio/dhive
- You can install dhive by running following command.
npm i @hiveio/dhive
How to initialize dhive client?
- I've created a separate file named
dhive_client.js
file - Content of it are as follows.
- I've added multiple API endpoints.
var dhive = require("@hiveio/dhive");
var client = new dhive.Client([
"https://api.hive.blog",
"https://api.deathwing.me",
"https://hive-api.arcange.eu",
"https://hived.emre.sh",
"https://api.openhive.network",
"https://rpc.ausbit.dev",
"https://rpc.mahdiyari.info",
"https://hive-api.3speak.tv",
"https://techcoderx.com",
]);
module.exports = {
client,
};
How to fetch notifications of an account using dhive library?
- I would recommend creating a separate file
- I created
get_notifications.js
file - Here are the content for it.
- NOTE: I tried sending limit above 100 & it failed.
- So, limit must not exceed 100.
async function getNotifications(client, account) {
try {
let data = await client.call("bridge", "account_notifications", {
account: account, //"sagarkothari88",
limit: 100,
});
return data;
} catch (e) {
return false;
}
}
module.exports = {
getNotifications,
};
- With above function in place, now you can easily getNotifications for any account.
- Note that, I've used
sagarkothari88
as account name. - You can use any account name / hive user.
- It must not include
@
sign. - If there is some error getting notifications, above function will simply return false.
const { client } = require("./dhive_client");
const { getNotifications } = require("./helper/get_notifications");
async function mainFunction() {
const account = "sagarkothari88";
const data = await getNotifications(client, account);
console.log(`Notifications data - ${JSON.stringify(data)}`);
}
mainFunction();
QUIZ time
- 50 Ecency Points - What's the better way to send an error, instead of returning false?
- 50 Ecency Points - Explicit link of Hive API docs (https://developers.hive.io/apidefinitions) which provides sample cURL to achieve the same.
- 50 Ecency Points - Can you provide filter
type
to get the notifications filtered?
QUIZ rules
- Anyone can participate
- Those, who provide first valid answer, will be rewarded.
- One person can be rewarded max for one answer.
- Only if there are no more participants, rewards can go to the same person
- If no participants, no rewards.
Support Me
- Vote me as Hive Witness
- I support following communities & recommend joining
Cheers,
Have a good one.
0
0
0.000
Congratulations @sagarkothari88! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)
Your next target is to reach 46000 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
To support your work, I also upvoted your post!
Another quicker way to access Hive data is with hivexplorer.com which utilizes dhive to give you easier REST API https://hivexplorer.com/api-docs
Example here:
https://hivexplorer.com/api/account_notifications?account="sagarkothari88"&limit=10
Nice. I wasn't aware of this. This is amazing.
Thank you for sharing.
Wow, this is awesome. Seeing it for the first time. Who made this?
Edit: Found out that it was made by your team. Nice work guys.
The Hive.Pizza team manually curated this post.
Please vote for pizza.witness!
Cool! What I needed & cool concept with the quiz! I love it! I don't have the time to check out your account right now, but will be happy to discover you later in the feed again and check out more exciting stuff!
Awesome! I like this kind of articles!