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?
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 ( ) ;
source
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
Cheers,
Have a good one.