Skip to content

[mkdocs] docs: add listen new blocks tutorial#910

Open
zero4862 wants to merge 2 commits into
NemProject:new-docsfrom
zero4862:docs-listen-new-blocks
Open

[mkdocs] docs: add listen new blocks tutorial#910
zero4862 wants to merge 2 commits into
NemProject:new-docsfrom
zero4862:docs-listen-new-blocks

Conversation

@zero4862

Copy link
Copy Markdown

Adapt listen new blocks tutorial to NEM.

@zero4862 zero4862 requested a review from segfaultxavi June 23, 2026 15:29
For each message, the snippet prints two of its fields:

* `height`: The height of the new block.
* `signer`: The public key of the <harvester account:> that produced the block.

@zero4862 zero4862 Jun 23, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlike Symbol, NEM doesn't return the block hash in the response, so I'm printing the harvester public key instead.

A NEM block does not include its own hash in this payload, so this tutorial identifies each block by its `height`
and also prints the harvester's `signer`.

!!! warning "New blocks are not yet final"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlike Symbol, I'm not showing how to determine whether a block is irreversible, since NEM has no dedicated channel for it. Instead, I'm linking to the polling tutorial, where it's already explained in enough detail.

print(f'Using node {NODE_URL}')


# SockJS has no Python client library.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no sockjs-client library for Python, so I had to write some helper functions to achieve the same functionality as in JavaScript.

import { Client } from '@stomp/stompjs';
import SockJS from 'sockjs-client';

const NODE_URL = process.env.NODE_URL || 'http://ntn1.dusanjp.com:7778';

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using this other node because libertalia does not have websockets enabled at 7778. I'm asking in discord if there's a way to enable them for consistency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant