Listening to new blocks

Get notified when a new block is included.

Prerequisites

Let’s get into some code

const listener = new Listener('http://localhost:3000');

listener.open().then(() => {

    listener
        .newBlock()
        .subscribe(block => console.log(block), err => console.error(err));

});
const listener = new Listener('http://localhost:3000');

listener.open().then(() => {

    listener
        .newBlock()
        .subscribe(block => console.log(block), err => console.error(err));

});
nem2-cli monitor block

Note

The listener implementation changes when used on the client side (e.g., Angular, React, Vue).