1. Home
  2. bloXroute Documentation
  3. Transaction Streaming
  4. Creating a Subscription

Creating a Subscription

Subscriptions are created with the RPC call subscribe with the subscription name and subscription options set as parameters. Subscription options currently support filtering which fields you would like to include in the notification. The subscription options currently available include tx_hash and tx_contents. Omitting these options will include all fields.
 
If you are running your own Gateway, you can subscribe to transaction feeds provided by your Gateway. To connect, you’ll need to connect to the websocket server at ws://<gateway ip address>:28333.
 
If you are not running your own Gateway, then you can subscribe to transaction feeds provided by bloXroute’s Cloud-API. To connect, you’ll need to connect to the websocket server at wss://eth.feed.blxrbdn.com with the SSL certificate you received during account registration. subscribe returns a subscription ID that all related notifications will be paired with.

Subscribing to Gateway Feed Python code example:

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("pendingTxs", {"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)

 
Subscribing to Cloud-API Feed Python code example:

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("pendingTxs", {"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)