Creating a subscription

Streams are available with Websocket via both Gateway and Cloud-API. Subscriptions are created using 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.

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.


  • We assume that the Gateway IP is with default ws port 28333 in the example below.



Subscribing to Gateway Stream in Python (version 3.7 or higher):

import asyncio, websockets, json

async def main():
        auth_key = "YOUR_AUTHORIZATION_HEADER"
        async with websockets.connect(
        ) as websocket:
            request = json.dumps({"id": 1, "method": "subscribe", "params": ["newTxs", {"include": ["tx_hash"]}]})
            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__':

For more help subscribing to a Websocket stream, follow our step-by-step video walkthrough.

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

Last updated