Handling the Notification
After subscribing to a stream, your program receives a notification for each event (e.g. new transaction or block) being published in the stream.
When your code is ready to process a new transaction notification, it should call get_next_subscription_notification_by_id. You should pass the subscription_id returned from the subscribe command.
​

Examples

Gateway-API
Cloud-API (Enterprise)
Cloud-API (Non-Enterprise)
Handling the transaction notification from a Gateway Stream in Python (line 8 handles the notification):
1
from bloxroute_cli.provider.ws_provider import WsProvider
2
ws_uri = "ws://127.0.0.1:28333"
3
while True:
4
try:
5
async with WsProvider(ws_uri) as ws:
6
subscription_id = await ws.subscribe("newTxs", {"include": ["tx_hash"]})
7
while True:
8
next_notification = await ws.get_next_subscription_notification_by_id(subscription_id)
9
print(next_notification) # or process it generally
10
except Exception as e:
11
print(f"Connection broken to feed, {str(e)}, retrying.")
12
await ws.unsubscribe(subscription_id)
13
​
Copied!
Handling the transaction notification from a Cloud-API Stream in Python (line 7 handles the notification):
1
from bloxroute_cli.provider.cloud_wss_provider import CloudWssProvider
2
async with CloudWssProvider(
3
ssl_dir="/usr/bloxroute/certificate/external_gateway/registration_only"
4
) as ws:
5
subscription_id = await ws.subscribe("newTxs", {"include": ["tx_hash"]})
6
while True:
7
next_notification = await ws.get_next_subscription_notification_by_id(subscription_id)
8
print(next_notification) # or process it generally
9
await ws.unsubscribe(subscription_id)
10
Copied!
Handling the transaction notification from a Cloud-API Stream in Python (line 8 handles the notification):
1
from bloxroute_cli.provider.ws_provider import WsProvider
2
async with WsProvider(
3
uri="wss://api.blxrbdn.com/ws",
4
headers={"Authorization": <YOUR-AUTHORIZATION-HEADER>}
5
) as ws:
6
subscription_id = await ws.subscribe("newTxs", {"include": ["tx_hash"]})
7
while True:
8
next_notification = await ws.get_next_subscription_notification_by_id(subscription_id)
9
print(next_notification) # or process it generally
10
await ws.unsubscribe(subscription_id)
Copied!
Last modified 9mo ago
Copy link