How to Get Blockchain Version of Steem RPC Node using Javascript

  • Time:2020-09-07 12:26:38
  • Class:Weblog
  • Read:27
JS How to Get Blockchain Version of Steem RPC Node using Javascript? blockchain javascript SteemIt

NodeJs / Javascript

In the Load Balancer RPC Node: https://steem.justyy.workers.dev the return response contains a custom header version which is basically the Version of the RPC Node for the Invoked Steem Node. To obtain this information, it is basically the same as sending the following parameters to invoke the get_version api:

1
{"id":0,"jsonrpc":"2.0","method":"call","params":["login_api","get_version",[]]}
{"id":0,"jsonrpc":"2.0","method":"call","params":["login_api","get_version",[]]}

To wrap it in async Javascript Function – which returns the version string:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
async function getVersion(server) {
  return new Promise((resolve, reject) => {
    fetch(server, {
      method: "POST",
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({"id":0,"jsonrpc":"2.0","method":"call","params":["login_api","get_version",[]]})
    }).then(response => {
      resolve(response.text());
    }).catch(function(error) {
      reject(error);
    });
  });
}
async function getVersion(server) {
  return new Promise((resolve, reject) => {
    fetch(server, {
      method: "POST",
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({"id":0,"jsonrpc":"2.0","method":"call","params":["login_api","get_version",[]]})
    }).then(response => {
      resolve(response.text());
    }).catch(function(error) {
      reject(error);
    });
  });
}

To invoke it, we can do something like this:

1
2
3
4
(async function() {
    const ver = await getVersion("https://api.justyy.com");
    console.log(ver);
})();
(async function() {
    const ver = await getVersion("https://api.justyy.com");
    console.log(ver);
})();

This gives the following to the console:

1
2
3
4
{"jsonrpc":"2.0","result":{"blockchain_version":"0.23.1",
"steem_revision":"46c7d93db350e8b031a81626e727c92b27d7348b",
"fc_revision":"46c7d93db350e8b031a81626e727c92b27d7348b"},
"id":0}
{"jsonrpc":"2.0","result":{"blockchain_version":"0.23.1",
"steem_revision":"46c7d93db350e8b031a81626e727c92b27d7348b",
"fc_revision":"46c7d93db350e8b031a81626e727c92b27d7348b"},
"id":0}

The above code can be viewed and tested directly in the SteemJs Editor

–EOF (The Ultimate Computing & Technology Blog) —

Recommend:
Summits set epoch-making milestone in history of China-Arab ties
In the face of COVID-19 pandemic, China and Arab countries have
15 Macao residents qualify as candidates for deputies to nationa
Study finds genetic solution to pre-harvest sprouting in rice, w
Bodybuilders dying as coaches, judges encourage extreme measures
Malta's Marsaskala, China's Dujiangyan sign sister city agreemen
U.S. mortgage applications continue slide amid surging interest
Russian, UAE presidents discuss bilateral cooperation over phone
Hate crimes in U.S. Los Angeles County rise to highest level sin
Chinese mainland reports 4,031 new local confirmed COVID-19 case
Share:Facebook Twitter
Comment list
Comment add