Websocket
Creating a subscription
WebSocket connection
ws://127.0.0.1:28333/ws
wss://<region>.eth.blxrbdn.com #ETH
wss://<region>.bsc.blxrbdn.com #BSCwss://api.blxrbdn.com #ETHExamples
import asyncio, websockets, json
async def main():
try:
auth_key = "YOUR_AUTHORIZATION_HEADER"
async with websockets.connect(
'ws://127.0.0.1:28333/ws',
additional_headers={"Authorization" : 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())Last updated