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.
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.
Copy ws://127.0.0.1:28333/ws
Authentication method: Use authorization header .
Copy wss://<region>.eth.blxrbdn.com #ETH
wss://<region>.bsc.blxrbdn.com #BSC
Gateway Cloud-API (Enterprise) Cloud-API (Non Enterprise)
Subscribing to Gateway Stream in Python (version 3.7 or higher):
Copy import asyncio , websockets , json
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)],
) 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):
Copy import asyncio , json , 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)],
) 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):
Copy import asyncio , json , websockets
async def main ():
try :
auth_key = "YOUR_AUTHORIZATION_HEADER"
async with websockets . connect (
'wss://api.blxrbdn.com/ws' ,
header = [ "Authorization: {} " . format (auth_key)],
) 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 ())