Creating a Subscription

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.

WebSocket connection

Before using the subscribe call, you need to open a websocket connection to the Gateway or the Cloud-API.

Gateway
Cloud-API
Gateway

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
​

​

Cloud-API

Enterprise Plan:

wss://eth.feed.blxrbdn.com:28333 #ETH
wss://bsc.feed.blxrbdn.com:28333 #BSC

Developer or Professional Plan:

wss://api.blxrbdn.com/ws

Examples

Gateway
Cloud-API (Enterprise)
Cloud-API (Non Enterprise)
Gateway

Subscribing to Gateway Stream in Python (line 6 creates the subscription):

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("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)
​
Cloud-API (Enterprise)

Subscribing to Cloud-API Stream in Python (line 5 creates the subscription):

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("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)
Cloud-API (Non Enterprise)

Subscribing to Cloud-API Feed in Python (line 6 creates the subscription):

from bloxroute_cli.provider.ws_provider import WsProvider
async 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 generally
await ws.unsubscribe(subscription_id)
​

Please check newTxs and pendingTxs for examples in wscat, node.js and Golang.