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]
Great work !
Thank's
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit