Javascript Code For Working With Hive, Steem And Blurt
Previous Version
Before HF24, Hive property names were the same as those from Steem, and the library that I used was this one: @droida/3-blockchains-1-program.
After that, symbols and property names changed, and some API calls were not working using the same require instruction. So I had to adapt my scripts.
Because I wanted to make the minimal amount of change in my existing scripts, I use newhive as argument for operations not working with the Steem library, eg transfer. Here is my library for working with the 3 blockchains.
chainlib.js
var currentChainName="steem";
const chain=require("steem");
const hive=require("@hiveio/hive-js");
module.exports = {
/**
* @argument {String} name the blockchain name (newhive for transfer and claim rewards)
*/
getChain: function(name) {
if (name && name!=currentChainName) {
currentChainName=name;
if (name=='steem') {
chain.api.setOptions({ url: 'https://api.steemit.com' });
chain.config.set('address_prefix','STM');
chain.config.set('chain_id','0000000000000000000000000000000000000000000000000000000000000000');
chain.config.set('alternative_api_endpoints', ['https://api.steemit.com', 'https://api.steemit.com']);
return chain;
} else if (name=='hive') {
chain.api.setOptions({ url: 'https://api.hive.blog' });
chain.config.set('address_prefix','STM');
chain.config.set('chain_id','beeab0de00000000000000000000000000000000000000000000000000000000');
chain.config.set('alternative_api_endpoints', ['https://api.openhive.network', 'https://rpc.esteem.app']);
chain.config.set('rebranded_api', true);
//chain.broadcast.updateOperations() // not needed anymore
return chain;
} else if (name=='newhive') {
hive.api.setOptions({ url: 'https://api.hive.blog' });
hive.config.set('address_prefix','STM');
hive.config.set('chain_id','beeab0de00000000000000000000000000000000000000000000000000000000');
hive.config.set('alternative_api_endpoints', ['https://api.openhive.network', 'https://rpc.esteem.app']);
hive.config.set('rebranded_api', true);
return hive;
} else if (name=='blurt') {
chain.api.setOptions({ url: 'https://rpc.blurt.world', useAppbaseApi: true });
chain.config.set('address_prefix','BLT');
chain.config.set('chain_id','cd8d90f29ae273abec3eaa7731e25934c63eb654d55080caff2ebb7f5df6381f');
chain.config.set('alternative_api_endpoints', ['https://blurtd.privex.io', 'https://api.blurt.blog']);
return chain;
}
}
return chain;
},
getChainName: function() {
if (currentChainName=="newhive") {
return "hive";
}
return currentChainName;
},
getSymbol: function() {
switch (currentChainName) {
case 'steem':
return "STEEM";
case 'hive':
case 'newhive':
return "HIVE";
case 'blurt':
return "BLURT";
}
},
getStableSymbol: function() {
switch (currentChainName) {
case 'steem':
return "SBD";
case 'hive':
case 'newhive':
return "HBD";
}
},
getPowerSymbol: function() {
switch (currentChainName) {
case 'steem':
return "SP";
case 'hive':
case 'newhive':
return "HP";
case 'blurt':
return "BP";
}
},
getPrefix: function() {
return module.exports.getChainName()+"_";
},
getStablePrefix: function() {
var stableSymbol=module.exports.getStableSymbol();
if (stableSymbol) {
return stableSymbol.toLowerCase()+"_";
}
}
};
Example
The blockchain name is passed as a command line argument.
#!/usr/bin/node
const chainlib=require("./chainlib.js");
const chain=chainlib.getChain(process.argv[2]);
chain.api.getDynamicGlobalProperties(function(err, result) {
console.log(err, result);
});
Quicktrades
I published this small library mainly because now uses it for trading in Hive and Steem internal markets. The release will be out in the coming days.
Leave Javascript Code For Working With Hive, Steem And Blurt to:
Read more #javascript posts
Best Posts From Droida
We have not curated any of droida's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From Droida
- Curation Rewards Shares Of May 2026 Are Payed
- Curation Rewards Shares Of April 2026 Are Payed
- Curation Rewards Shares Of March 2026 Are Payed
- Vote to Protect the Value of Hive
- Curation Rewards Shares Of February 2026 Are Payed
- Curation Rewards Shares Of January 2026 Are Payed
- Curation Rewards Shares Of December 2025 Are Payed
- Curation Rewards Shares Of November 2025 Are Payed
- Curation Rewards Shares Of October 2025 Are Payed
- Curation Rewards Shares Of September 2025 Are Payed
- Curation Rewards Shares Of August 2025 Are Payed
- 1,000 Blacklisted Accounts
- Curation Rewards Shares Of July 2025 Are Payed
- Curation Rewards Shares Of June 2025 Are Payed
- Curation Rewards Shares Of May 2025 Are Payed
- Curation Rewards Shares Of April 2025 Are Payed
- Curation Rewards Shares Of March 2025 Are Payed
- Curation Rewards Shares Of February 2025 Are Payed
- Curation Rewards Shares Of January 2025 Are Payed
- Curation Rewards Shares Of December 2024 Are Payed