Hello Everyone
As you know in the previous posts we have discussed Hivejs and a little bit of dhive. We tried to perform some tasks with Hivej in the previous posts like voting, posting getting account history, etc. In this post, we are going to write a code that will show the voting MANA and the RC( Resource Credit) of any account. This is very useful like when you are performing a task like an account claiming , voting through JavaScript and you want to check the RC/MANA level before perform the specific task so you can check the MANA percentage and then perform the task. So without wasting more time let's start the tutorial.
- First of all, We need the latest version of Node.js. If you don't have the Nodejs installed please download it from the official site of Node.js.
- After installing the node.js. Open the VS code.
- Create a folder and open it in the VS code and create a js file.(index.js)
- Now go to terminal and type
npm init
. This will ask for some info( optional you can just press enter, enter to skip with default)
- Now we need to install the Hive Library ( dhive). In order to install dhive paste the command in the terminal.
npm install @hivechain/dhive
. This will download the necessary file from the Node Package Module.
- To check the files are downloaded or not you can check the dependencies in the pakage.json and also the node_Modules folder.
- Now we are good to write our script.
As you can see this is returning a promise. So we can use Async/Await to get our RC.
- you can see three properties there. As we need the percentage so
hiverc.percentage
will return the percentage but still, we need to divide it by 100 in order to obtain an accurate and understandable percentage. Sohiverc.percentage/100
Now to check the Voting Mana we just need a little change.
Script
const dhive = require('@hivechain/dhive');
var hClient = new dhive.Client('https://api.hive.blog');
let account='YOUR_ACCOUNT_NAME'
async function check(){
let hiverc = await hClient.rc.getRCMana(account);
let hiveMana= await hClient.rc.getVPMana(account);
console.log(`Voting percentage of ${account} is ${hiveMana.percentage/100}% and RC = ${hiverc.percentage/100}%`);
}
check();
I think this much is enough for today. Now if you like the post please upvote and comment if you want to give me some advise