Links

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.
ws://127.0.0.1:28333/ws
Authentication method: Use authorization header.
wss://<region>.eth.blxrbdn.com #ETH
wss://<region>.bsc.blxrbdn.com #BSC
wss://<region>.polygon.blxrbdn.com #Polygon
Authentication method: Use authorization header.
wss://api.blxrbdn.com #ETH

Examples

Gateway
Cloud-API (Enterprise)
Cloud-API (Non Enterprise)
Subscribing to Gateway Stream in Python (version 3.7 or higher):
import asyncio, websockets, json, ssl
async def main():
try:
auth_key = "YOUR_AUTHORIZATION_HEADER"
async with websockets.connect(
'ws://127.0.0.1:28333/ws',
header=["Authorization:{}".format(auth_key)],
sslopt={"cert_reqs": ssl.CERT_NONE},
) as websocket:
request = json.dumps({"id": 1, "method": "subscribe", "params": ["newTxs", {"include": ["tx_hash"]}]})
websocket.send(request)
while True:
response = json.loads(websocket.recv())
print(response) # or process it generally
except Exception as e:
print(f'Connection failed, Reason: {e}')
if __name__ == '__main__':
asyncio.run(main())
Subscribing to Cloud-API Feed in Python (version 3.7 or higher):
import asyncio, json, ssl, websockets
async def main():
try:
auth_key = "YOUR_AUTHORIZATION_HEADER"
async with websockets.connect(
'wss://virginia.eth.blxrbdn.com/ws',
header=["Authorization:{}".format(auth_key)],
sslopt={"cert_reqs": ssl.CERT_NONE},
) as websocket:
subscription_request = json.dumps({"id": 1, "method": "subscribe", "params": ["newTxs", {"include": ["tx_hash"]}]})
await websocket.send(subscription_request)
while True:
response = await websocket.recv()
print(response)
except Exception as e:
print(f'Connection failed, Reason: {e}')
if __name__ == '__main__':
asyncio.run(main())
Subscribing to Cloud-API Feed in Python (version 3.7 or higher):
import asyncio, json, ssl, websockets
async def main():
try:
auth_key = "YOUR_AUTHORIZATION_HEADER"
async with websockets.connect(
'wss://api.blxrbdn.com/ws',
header=["Authorization:{}".format(auth_key)],
sslopt={"cert_reqs": ssl.CERT_NONE},
) as websocket:
subscription_request = json.dumps({"id": 1, "method": "subscribe", "params": ["newTxs", {"include": ["tx_hash"]}]})
await websocket.send(subscription_request)
while True:
response = await websocket.recv()
print(response)
except Exception as e:
print(f'Connection failed, Reason: {e}')
if __name__ == '__main__':
asyncio.run(main())
Please check newTxs and pendingTxs for examples in wscat, node.js and Golang.