1. Home
  2. bloXroute Documentation
  3. Transaction Streaming
  4. Handling the Transaction Notification

Handling the Transaction Notification

After subscribing to a stream, your program receives a notification for each new transaction 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.

The returned transaction is formatted as JSON.

Handling the transaction notification from a Gateway Feed Python code example:

from bloxroute_cli.provider.ws_provider import WsProvider
ws_uri = "ws://127.0.0.1:28333"
while True:
   try:
       async with WsProvider(ws_uri) as ws:
           subscription_id = await ws.subscribe("pendingTxs", {"include": ["tx_hash"]})
           while True:
               next_notification = await ws.get_next_subscription_notification_by_id(subscription_id)
               print(next_notification)  # or process it generally
   except Exception as e:
       print(f"Connection broken to feed, {str(e)}, retrying.")
await ws.unsubscribe(subscription_id)

 

Handling the transaction notification from a Cloud-API Feed Python code example:

from bloxroute_cli.provider.cloud_wss_provider import CloudWssProvider
async with CloudWssProvider(
    ssl_dir="/usr/bloxroute/certificate/external_gateway/registration_only"
) as ws:
    subscription_id = await ws.subscribe("pendingTxs", {"include": ["tx_hash"]})
    while True:
        next_notification = await ws.get_next_subscription_notification_by_id(subscription_id)
        print(next_notification)  # or process it generally
    await ws.unsubscribe(subscription_id)