How to Get Blockchain Version of Steem RPC Node using Javascript
- 时间:2020-09-07 12:26:38
- 分类:网络文摘
- 阅读:113 次

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) —
推荐阅读:黑木耳营养丰富对健康有五大好处 香蕉和橘子能起到解毒护肝的作用 吃葡萄、喝葡萄酒能帮助调节性功能 绿茶、红茶、青茶、黑茶、白茶和黄茶 奶茶多添加奶精 长期食用会引发心脏病 奶茶调查:街头奶茶店调香味多用奶精 适合秋天食用的养肺食谱可滋阴润肺 哪些食物可以起到止咳润肺的作用 食物的禁忌:中医如何区分食物的寒热性 味道鲜美营养丰富的黑木耳最佳吃法
- 评论列表
-
- 添加评论