Hivejs Tutorials-- Introduction || For Beginners

Hello Everyone!

As you know the Hivejs is migrated to Hive Blockchain. In this post we will understand what can we do with Hivejs and How can we interact with Hive Blockchain. If you don't know what Hivejs is. Hivejs is Hive official Javascript library for Hive Blockchain. Every tool/app you use to access hive features almost use hivejs. So Let's start the tutorial with installations of Hivejs but before we start I should tell you that this post is for absolute beginner who knows Javascript little bitt but don't how to use Hivejs.

image.png

Installtions.

First of all we need the latest version of Node.js. Go to Node.js page and downlaod the Node.js .
image.png

After the installation opens the Visual Studio code. If you don't have Visual studio install then go to VS code page and download the latest version of Vs code. You can use any other IDE but I recommend VS code.

image.png

Open the terminal.

image.png

In the terminal run the command. npm install @hiveio/hive-js --save.
image.png

Wait for some time let the files downloaded. After the file is saved create a new file with name Index.js.

image.png

open the index.js (The file we just created). We will write and run our code here. The first thing we will do is to get the Hive account information using Hivels.

var hive= require('@hiveio/hive-js');

var username="YOUR-USER-NAME-HERE";

hive.api.getAccounts([username], function(err, response){
  console.log(err, response);
});

Run the following command to access the data of any hive user. Assign the name of user you want to check to the username variable. In my case I am going to try my own username which @pakgamer.

image.png

Now as it returns an object then we can access its object. For Example, I just want to print Hive balance of my account then I will run this.

var hive= require('@hiveio/hive-js');

var username="pakgamer";

hive.api.getAccounts([username], function(err, response){
  
  console.log(err, response[0].balance);
});

image.png

And to check the HBD amount in my account we can just dod this.

image.png

We can do pretty cool things with this Hivejs. In the upcoming post we will check what else we can do with hivejs.
ntitled-1.png

H2
H3
H4
3 columns
2 columns
1 column
5 Comments
Ecency