Subscriptions are created with the RPC call subscribe
with the stream (feed) name and subscription options set as parameters. Each stream has a different subscription name and can accept different subscription options. Please refer to the specific stream page for info. For more help subscribing to a stream, follow our step-by-step video walkthrough.
subscribe
returns a subscription ID that will be paired with all related notifications.
Before using the subscribe call, you need to open a websocket connection to the Gateway or the Cloud-API.
Notes:
We assume that the Gateway IP is 127.0.0.1 with default ws port 28333 in the example below.
ws://127.0.0.1:28333
Enterprise Plan:
Authentication method: Use SSL certificate you received during account registration.
wss://eth.feed.blxrbdn.com:28333
Developer or Professional Plan:
Authentication method: Use authorization header.
wss://api.blxrbdn.com/ws
Subscribing to Gateway Stream in Python (line 6 creates the subscription):
from bloxroute_cli.provider.ws_provider import WsProviderws_uri = "ws://127.0.0.1:28333"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 generallyexcept Exception as e:print(f"Connection broken to feed, {str(e)}, retrying.")await ws.unsubscribe(subscription_id)
Subscribing to Cloud-API Stream in Python (line 5 creates the subscription):
from bloxroute_cli.provider.cloud_wss_provider import CloudWssProviderasync with CloudWssProvider(ssl_dir="/usr/bloxroute/certificate/external_gateway/registration_only") 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 generallyawait ws.unsubscribe(subscription_id)
Subscribing to Cloud-API Feed in Python (line 6 creates the subscription):
from bloxroute_cli.provider.ws_provider import WsProviderasync with WsProvider(uri="wss://api.blxrbdn.com/ws",headers={"Authorization": <YOUR-AUTHORIZATION-HEADER>}) 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 generallyawait ws.unsubscribe(subscription_id)