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));

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

        listener.open().get();

        BlockInfo blockInfo = listener.newBlock().take(1).toFuture().get();

        System.out.println(blockInfo);
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).