API Reference

Listen to new data as it arrives.

Endpoint: wss://api.syve.ai/v1/ws

Introduction

Websockets provide real-time, bidirectional communication between a client and server. To start listening to new data arriving you need to send a subscription message.

Subscription message syntax

The subscription message must be JSON. The format of subscription messages we accept is as follows.

{
    "method": "subscribe",
    "table": "<table_name>",
}

Here table_name specifies which table to filter on. Possible values for table_name are given in section below.

Possible values for table_name

📘

Data you can listen to

You can listen to new data for all our tables. For a list of all available tables see the Data Tables section of the API reference.

NameChainReference
Ethereum BlocksEthereumeth_blocks
Ethereum DEX TradesEthereumeth_dex_trades
Ethereum ERC20 TransfersEthereumeth_erc20
Base BlocksBasebase_blocks
Base DEX TradesBasebase_dex_trades
Base ERC20 TransfersBasebase_erc20

Example

Request

Example using wscat

# initiate websocket stream first
wscat -c wss://api.syve.ai/v1/ws

# then call subscription 
{"method": "subscribe", "table": "eth_blocks"}

To run the above in a terminal you need to have wscat installed. To install wscat run: sudo npm install -g wscat. Make sure node and npm are also installed.

Example using python

import asyncio
import json
import websockets

async def connect():
    uri = "wss://api.syve.ai/v1/ws"

    async with websockets.connect(uri) as ws:
        # Subscribe to eth_blocks table
        subscription_data = {"method": "subscribe", "table": "eth_blocks"}
        await ws.send(json.dumps(subscription_data))

        while True:
            # Wait for data from the server
            response = await ws.recv()
            print(f"Received data: {response}")

if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(connect())

Response

{
   "block_number":18106820,
   "records":[
      {
         "block_number":18106820,
         "block_hash":"0x89b7fffb84a627a16d6c7aa06dd508b80e2e713cd2aa29c3e2c7c84a2d542e5f",
         "@timestamp":1694359103,
         "parent_hash":"0x4e4f683b34120ad76c27eae78910d09e7ed76cffb15fcd7810387abe773df306",
         "mix_hash":"0xc3f491f4841662d0e45943e8cfa285c20923a983747bc1d5749bb8498fe9a763",
         "nonce":"0x0000000000000000",
         "sha3_uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
         "difficulty":0,
         "total_difficulty":58750003716598352816469,
         "size_bytes":315655,
         "base_fee_per_gas_gwei":11.5571842,
         "gas_limit":30000000,
         "gas_used":20408028,
         "transactions_count":146,
         "miner_address":"0x602f2e120a9956f2ad1ce47ced286fcefbba9f8c",
         "uncle_count":0
      }
   ]
}