Steem-lib Guide [Part1]
Remote.js is the point of entry for interacting with Steem
Servers Setting
to set multiple-servers, with login parameters:
var Remote = require('steem-lib').Remote;
var remote = new Remote({
servers: [
{
url: 'wss://steemd.steemit.com',
primary: true,
username: '',
password: '',
},
{
url: 'wss://steemnode.mydomain.com',
username: 'myname',
password: 'pw123',
}
]
});
If any server been set as 'primary', all API calls will be send to it, unless it's gone off-line then the requests will be directed to other servers. If no server is set as primary, the Remote instance will choose one base on a scoring.
If there's no username/password required for a server, pass in its url string will do:
var remote = new Remote({
servers: ['wss://node.steem.ws', 'wss://steemd.steemit.com']
})
Initiate connection:
remote.connect(function (){
console.log('connected to steem servers.');
})
once connect, Remote will try to stay connected to every servers... i.e. whenever a connection is closed, it will automatic try to reconnect.
to manually stop all connection:
remote.disconnect();
Making Api Call
Remote has a method for every Steem APIs.
remote.get_account_history('ripplerm', -1, 10, function(err, res) {
console.log(err || res);
});
equivalent method in camelCase:
remote.getAccountHistory('ripplerm', -1, 10, function(){});
optionally, to pass arguments in single object, append the method with 'With':
remote.getAccountHistoryWith({
account: 'ripplerm',
from: -1,
limit: 10
}, function(err, res){
console.log(err, res)
});
Remote events
- 'connect' - when connected to first server.
- 'disconnect' - when all servers are offline.
- 'block_advanced' - when there's a new last_irreversible_block.
remote.on('block_advanced', function (num) {
console.log('last_irreversible_block_num =', num);
})
events emited when using Remote.stream().
- 'block' - new irreversible_block
- 'transaction' - new txn into irreversible_block
remote.on('block', function (block) {
//process block object...
})
remote.on('transaction', function (txn) {
//process txn...
})
remote.startStream();
streaming block_header (for head blocks):
remote.streamBlockHeader(function (blockHeader){
console.log('headblock num:', Remote.getBlockNum(blockHeader));
console.log('headblock id:', Remote.getBlockId(blockHeader));
})
Next: Steem-lib Guide [Part2]
Leave Steem-lib Guide [Part1] to:
Read more #steem-lib posts
Best Posts From ripplerm
We have not curated any of ripplerm'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 ripplerm
- [Steemiex] A new Ripple Gateway for Steem (alpha launch)
- [Steemiex Guide] Adding New Currency-Pair (Market) in Gatehub-wallet
- [Steemiex Guide] Withdraw from Ripple-network to Steem-blockchain
- [Steemiex Guide] Deposit from Steem to Ripple-network
- [Steemiex Guide] How to set Trustlines to Steemiex
- XRP-Giveaway for Steem Users
- [Ripple-Wallet Guide] Trading / Exchange
- [Ripple-Wallet Guide] Making Payment
- [Ripple-Wallet Guide] Managing Trustlines
- [Ripple] Understanding passphrase, secret-key, and address (account).
- [Ripple-Wallet Guide #2] Account Info
- [Ripple-Wallet Guide #1] Overview, Network, Account.
- [Ripple Wallet] - Introduction.
- [Experiment] The Born of a Top Voting Bot
- [Proposal] Decoupling Curation Rewards from Post's
- Steem-lib Guide [Part3]
- Story About Farm Workers
- Steem-lib Guide [Part2]
- Steem-lib Guide [Part1]
- Steem-lib, Intro.