FactomJS Contribution - FactomEventEmitter

You are viewing an older update. There is a newer update available.
Previous Update: FactomJS Contribution - FactomEventEmitter
I contributed the new FactomEventEmitter class to the FactomJS library. FactomEventEmitter lets you listen for various Factom events without needing to handle polling logic yourself. It simplifies writing applications that react to on-chain events. The following snippet demonstrates the on-chain events you can listen to.

JavaScript:
const { FactomCli, FactomEventEmitter } = require('factom');
const cli = new FactomCli();
// Poll the blockchain every 10s
const emitter = new FactomEventEmitter(cli, { interval: 10000 });
emitter.on('newDirectoryBlock', (directoryBlock) => ...);
emitter.on('newFactoidBlock', (factoidBlock) => ...);
emitter.on('newAdminBlock', (adminBlock) => ...);
emitter.on('newEntryCreditBlock', (entryCreditBlock) => ...);
emitter.on('newChain', (entryBlock) => ...);
// Listen to any transaction involving a given Factoid address
emitter.on('FA29eyMVJaZ2tbGqJ3M49gANaXMXCjgfKcJGe5mx8p4iQFCvFDAC', (transaction) => ...);
// Listen to any new entries in a given chain
emitter.on('4060c0192a421ca121ffff935889ef55a64574a6ef0e69b2b4f8a0ab919b2ca4', (entryBlock) => ...);
https://github.com/PaulBernier/factomjs/blob/master/src/factom-event-emitter.js

Thank you very much to @Paul Bernier for providing thorough code review and feedback.
 
Last edited:
You are viewing an older update. There is a newer update available.
Top