Published: 19 Jun 2023 › Updated: 19 Jun 2023
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
dhiveusing 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.jsfile - 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.jsfile - 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
sagarkothari88as 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
typeto 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.
Leave How to use @dhive/dhive library? to:
Read more #hive-139531 posts
Best Posts From Sagar Kothari
We have not curated any of sagarkothari88's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From Sagar Kothari
- HiveSuite Dev Update: Smart Mentions, Internal Navigation & Seamless Inline Media Experience.
- HiveReactKit Dev Update: Inline Media Playback, Enhanced Embeds & Cleaner Post Experience.
- HiveReactKit Dev Update: Smart @Mentions, Composer Intelligence & Improved In-App Navigation
- HiveSuite Dev Update: Bookmarks, Backend Improvements & Development Workflow Enhancement
- HiveSuite Dev Update: Advanced Bookmark System & Video Progress Experience.
- HiveSuite Dev Update: Reward Popup Accuracy, Translation Fixes & Video Progress Improvements
- HiveReactKit Dev Update: Universal Bookmarking & Improved Draft Management
- HiveReactKit Dev Update: Translation Controls, Mobile Safe Areas & IPFS Media Rendering
- HiveSuite Dev Update: Push Notifications, Scheduling Improvements & Draft Reliability
- HiveSuite Dev Update: Drafts Workspace, Scheduled Posts & Push Notification Support