RPC WebSocket Support (BETA)

Compute Unit (CU) values are subject to change as we assess and adjust our pricing to better reflect usage and associated costs.

Blockdaemon's RPC API supports WebSocket connections for real-time blockchain data on supported chains. This guide covers how to connect, which methods are available, and how Compute Units (CUs) are calculated.

Supported Chains

Chain Group Chains
Ethereum-Compatible Ethereum, Base, Polygon, Arbitrum, Avalanche, Optimism
Solana Solana
Polkadot Polkadot, Kusama

WebSocket Methods & Compute Units

Non-subscription RPC methods over web-socket connection are billed the same as regular RPC methods over HTTP.

Ethereum-Compatible Chains

Supported Methods Event Types Compute Units
eth_subscribe logs 30 CU per block
newHeads 5 CU per message
newPendingTransactions 20 CU per second
eth_unsubscribe

The minimum charge is 1 CU per action.

Billing Example – Subscribe to eth_subscribe with newHeads

Description Count CU per Action Total CU
🔼 Open WebSocket connection 1 1 CU 1
🔼 Send eth_subscribe request 1 1 CU 1
🔽 Receive confirmation from node 1 1 CU 1
🔽 Receive newHeads messages 5 10 CU 50
🔼 Send eth_unsubscribe request 1 1 CU 1
🔽 Receive unsubscribe confirmation 1 1 CU 1
Total Compute Units 55 CU

Solana

Supported Methods CU per Subscription Subscribes To CU per Message
accountSubscribe 1 CU accountNotification 5 CU
accountUnsubscribe 1 CU
logsSubscribe 1 CU logsNotification 5 CU
logsUnsubscribe 1 CU
programSubscribe 1 CU programNotification 10 CU
programUnsubscribe 1 CU
signatureSubscribe 1 CU signatureNotification 5 CU
signatureUnsubscribe 1 CU
slotSubscribe 1 CU slotNotification 5 CU
slotUnsubscribe 1 CU
slotsUpdatesSubscribe 1 CU slotsUpdatesNotification 5 CU
slotsUpdatesUnsubscribe 1 CU

- Subscribe / Unsubscribe request: 1 CU per request - Confirmation responses: 1 CU - Event messages (e.g., slotNotification): CU varies by event type

Each subscription type has a specific event type tied to it. For example, you send slotSubscribe → you’ll receive messages of type slotNotification.

Billing Example – Subscribe to accountSubscribe and receive accountNotification

Description Count CU per Action Total CU
🔼 Send accountSubscribe request 1 1 CU 1
🔽 Receive confirmation response 1 1 CU 1
🔽 Receive accountNotification messages 8 5 CU 40
🔼 Send accountUnsubscribe request 1 1 CU 1
🔽 Receive unsubscribe confirmation 1 1 CU 1
Total Compute Units 44 CU

Polkadot

Supported Methods CU per Subscription Subscribes To CU per Message
beefy_subscribeJustifications 1 CU beefy_justifications 1 CU
beefy_unsubscribeJustifications 1 CU
chain_subscribeFinalizedHeads 1 CU chain_finalizedHead 1 CU
chain_unsubscribeFinalizedHeads 1 CU
chain_subscribeAllHeads 1 CU chain_allHead 1 CU
chain_unsubscribeAllHeads 1 CU
chain_subscribeNewHeads 1 CU chain_newHead 1 CU
chain_unsubscribeNewHeads 1 CU
grandpa_subscribeJustifications 1 CU grandpa_justifications 1 CU
grandpa_unsubscribeJustifications 1 CU
state_subscribeRuntimeVersion 1 CU state_runtimeVersion 1 CU
state_unsubscribeRuntimeVersion 1 CU
state_subscribeStorage 1 CU state_storage 5 CU
state_unsubscribeStorage 1 CU

- Subscribe / Unsubscribe request: 1 CU per request - Confirmation responses: 1 CU - Event messages (e.g., chain_newHead): CU varies by event type

Each subscription type has a specific event type tied to it. For example, you send state_subscribeStorage → you’ll receive messages of type state_storage.

Billing Example – Subscribe to state_subscribeStorage and receive state_storage notifications

Description Count CU per Action Total CU
🔼 Send state_subscribeStorage request 1 1 CU 1
🔽 Receive confirmation response 1 1 CU 1
🔽 Receive state_storage notifications 6 5 CU 30
🔼 Send state_unsubscribeStorage request 1 1 CU 1
🔽 Receive unsubscribe confirmation 1 1 CU 1
Total Compute Units 34 CU

How to Connect

To connect to the WebSocket endpoint, follow these steps:

  1. Authorize your request using one of the following methods:

    Bearer Token

    curl --header "Authorization: Bearer YOUR_API_KEY"
    

    API Key

    curl --header "X-API-KEY: YOUR_API_KEY"
    
  2. You'll need to install a WebSocket client like wscat, or any other tool you prefer to connect.

    npm install -g wscat   //One-time installation
    ```

3. **Connect** to the WebSocket URL with the following URL pattern:

```undefined
    wss://svc.blockdaemon.com/:protocol/:network/native
    ```
    
    For example, for Ethereum Mainnet:
    
    ```undefined
    wscat --header "Authorization: Bearer YOUR_API_KEY" \
    -c wss://svc.blockdaemon.com/ethereum/mainnet/native
    ```

4. Once connected, you can **send and receive** messages using JSON-RPC:

JSON
    
    ```json
    // Subscribe to a WebSocket event (e.g., newHeads)
    {"jsonrpc":"2.0","method":"eth_subscribe","params":["newHeads"],"id":1}
    
    // Server responds with a subscription ID
    {"jsonrpc":"2.0","id":1,"result":"0xb544f3328760ac404b9e3a4aec6f2ec0"}
    
    // You’ll receive real-time updates as events happen
    {"jsonrpc":"2.0","method":"eth_subscription","params":{
      "subscription":"0xb544f3328760ac404b9e3a4aec6f2ec0",
      "result":{ /* event data */ }
    }}
    
    // To unsubscribe from the event stream
    {"jsonrpc":"2.0","method":"eth_unsubscribe","params":["0xb544f3328760ac404b9e3a4aec6f2ec0"],"id":2}
    
    // Confirmation that you’ve successfully unsubscribed
    {"jsonrpc":"2.0","id":2,"result":true}
    ```

## Need Help?

Contact us through [email](mailto:support@blockdaemon.com) or our [support page](/content/support/index.html) for any issues, bugs, or assistance you may need.