reviewing and practicing with steem api in javascript

in #steemdev6 years ago (edited)


hey steemians,

On Monday I published a publication about the title "the technology that is revolutionizing the web" in which I spoke about the importance of the javascript programming language and more about the programming with nodejs, which is a server back-end language also talk about the because this was of great importance for companies besides that leave my point of view of the best books to learn about this at the end of this publication I leave the link if you want to read it.
but this is not what is speaking in this publication, in this post will perform one tutorial of as using the api basic of steemit with javascript and nodejs installing the packages and things needed to perform the different tests.

separador

installation of necessary packages

first of all to use the api by javascript is necessary installed Steem.js installed in the browser is the following way :


< script src="./steem.min.js">< /script>

and on the server that side is where we will work is the following way

$ npm install steem --save

separador

once we have the necessary libraries we will proceed to perform the first consultation in which we will verify the last transaction made by a account in the blockchain of steem,to make this query we use the code that allows us to get the history of the accounts in steem, the code is as follows


steem.api.getAccountHistory(account, from, limit, function(err, result){
console.log(err, result);
});

but before explaining the operation of the code it is important to emphasize that in order to make any query we need to instantiate or create the steem object, we do it in the following way "var steem = require ('steem');" we do this to be able to use the different codes that are inside the libraries that we donwloading at the beginning of the post then the code would be exactly like that:


var steem = require ('steem');
steem.api.getAccountHistory(account, from, limit, function(err, result) {
console.log(err, result);
});

the code "steem.api.getAccountHistory" requires different factors which are necessary to make the query and show the transactions that is what we want to get, this factors are:

  • account: name of the account we want to see the transactions the name is written in quotes

  • from: this parameter indicates the point of start in the analizated of the transactions if they are negative numbers the transactions will be the most recent and the number in positive the transactions more ancient

  • limit: this is a limit of the transactions analyzed one point to have in consider is this number should never be greater than the previous parameter

once these parameters are configured the code will vote one code with the information required, this code have in its interior "arrays and JSON" already of there we will use the [] to move inside this. the information is within the "result" this is the variable that we will use to move within the different matrices and json that the query has made, the code would remain this way once we reached the point of operation:


var steem = require ('steem');
steem.api.getAccountHistory('ederaleng', -10, 3, function(error, result) {
var andres=result[1][1].op
console.log(andres)
});

in this point if save and run the file we will have the information we wanted to know in that transaction, so this is the end of my post I hope it has been helpful and outside of your liking


image sources 1

Coin Marketplace

STEEM 0.30
TRX 0.11
JST 0.033
BTC 64275.05
ETH 3147.49
USDT 1.00
SBD 4.29