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 (Enterprise)
Cloud-API (Non Enterprise)
Notes:
  • We assume that the Gateway IP is 127.0.0.1 with default ws port 28333 in the example below.
1
ws://127.0.0.1:28333
2
​
Copied!
​
Authentication method: Use authorization header.
1
wss://<region>.eth.blxrbdn.com #ETH
2
wss://<region>.bsc.blxrbdn.com #BSC
3
wss://<region>.polygon.blxrbdn.com #Polygon
Copied!
Authentication method: Use authorization header.
1
wss://api.blxrbdn.com #ETH
Copied!

Examples

Gateway
Cloud-API (Enterprise)
Cloud-API (Non Enterprise)
Subscribing to Gateway Stream in Python (line 6 creates the subscription):
1
from bxcommon.rpc.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!
Subscribing to Cloud-API Feed in Python (line 8 creates the subscription):
1
from bxcommon.rpc.provider.ws_provider import WsProvider
2
async with WsProvider(
3
uri="wss://virginia.eth.blxrbdn.com/ws",
4
headers={"Authorization": <YOUR-AUTHORIZATION-HEADER>},
5
# Add the following line if you work with IP instead of DNS
6
# skip_ssl_cert_verify=True
7
) as ws:
8
subscription_id = await ws.subscribe("newTxs", {"include": ["tx_hash"]})
9
while True:
10
next_notification = await ws.get_next_subscription_notification_by_id(subscription_id)
11
print(next_notification) # or process it generally
12
await ws.unsubscribe(subscription_id)
13
​
Copied!
Subscribing to Cloud-API Feed in Python (line 8 creates the subscription):
1
from bxcommon.rpc.provider.ws_provider import WsProvider
2
async with WsProvider(
3
uri="wss://api.blxrbdn.com/ws",
4
headers={"Authorization": <YOUR-AUTHORIZATION-HEADER>},
5
# Add the following line if you work with IP instead of DNS
6
# skip_ssl_cert_verify=True
7
) as ws:
8
subscription_id = await ws.subscribe("newTxs", {"include": ["tx_hash"]})
9
while True:
10
next_notification = await ws.get_next_subscription_notification_by_id(subscription_id)
11
print(next_notification) # or process it generally
12
await ws.unsubscribe(subscription_id)
13
​
Copied!
Please check newTxs and pendingTxs for examples in wscat, node.js and Golang.
Copy link
Contents