Links

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):
from bxcommon.rpc.provider.ws_provider import WsProvider
ws_uri = "ws://127.0.0.1:28333/ws"
while True:
try:
async with WsProvider(ws_uri) as ws:
subscription_id = await ws.subscribe("newTxs", {"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 Stream in Python (line 10 handles the notification):
from bxcommon.rpc.provider.ws_provider import WsProvider
async with WsProvider(
uri="wss://virginia.eth.blxrbdn.com/ws",
headers={"Authorization": <YOUR-AUTHORIZATION-HEADER>},
# Add the following line if you work with IP instead of DNS
# skip_ssl_cert_verify=True
) as ws:
subscription_id = await ws.subscribe("newTxs", {"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)
Handling the transaction notification from a Cloud-API Stream in Python (line 10 handles the notification):
from bxcommon.rpc.provider.ws_provider import WsProvider
async with WsProvider(
uri="wss://api.blxrbdn.com/ws",
headers={"Authorization": <YOUR-AUTHORIZATION-HEADER>},
# Add the following line if you work with IP instead of DNS
# skip_ssl_cert_verify=True
) as ws:
subscription_id = await ws.subscribe("newTxs", {"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)