Nodejs bindings for thalos
npm install --save @eosswedenorg/thalos-client
Pure javascript:
const thalos = require('@eosswedenorg/thalos-client');
// Create client.
const client = thalos.createRedisClient({
// url: "redis://localhost:6379",
// prefix: "ship",
ns: "1064487b3cd1a897ce03ae5b6a865651747e2e152090f99c1d19d44e01aea5a4" // wax mainnet
})
// Listen to heartbeat events.
client.onHeartbeat(hb => {
console.log("Hearbeat: Blockno", hb.blocknum, "HEAD", hb.head_blocknum, "LIB", hb.last_irreversible_blocknum);
});
With typescript:
import * as thalos from '@eosswedenorg/thalos-client';
// Create client.
const client = thalos.createRedisClient({
// url: "redis://localhost:6379",
// prefix: "ship",
ns: "1064487b3cd1a897ce03ae5b6a865651747e2e152090f99c1d19d44e01aea5a4" // wax mainnet
})
// Listen to heartbeat events.
client.onHeartbeat((hb:thalos.HeartBeat) => {
console.log("Hearbeat: Blockno", hb.blocknum, "HEAD", hb.head_blocknum, "LIB", hb.last_irreversible_blocknum);
});
More examples on how to use different event callback below:
Listening on transactions
// Listen on transactions
client.onTransaction(transaction => {
console.log("Transaction", transaction.id);
});
// Listen to one action.
client.onAction({contract: "m.federation", name: "mine"}, action => {
console.log("Mine Action", action);
});
// Listening on multiple actions.
client.onAction([ {contract: "eosio"}, {name: "mine"} ], action => {
console.log("Action", action);
});
Henrik Hautakoski - [email protected]