For the complete documentation index, see llms.txt. This page is also available as Markdown.

eth_subscribe - Somnia

Example code for the eth_subscribe JSON-RPC method. Complete guide on how to use eth_subscribe JSON-RPC in GetBlock Web3 documentation

This method creates a subscription over WebSocket on the Somnia network for real-time event notifications. Given Somnia's ~100ms block times and high throughput, subscriptions enable efficient real-time monitoring without polling. This method requires a WebSocket connection.

Parameters

Parameter
Type
Required
Description

subscriptionType

string

Yes

Type: "newHeads", "logs", "newPendingTransactions"

filterObject

object

No

Filter options (for "logs" type)

Subscription Types

  • newHeads - Subscribe to new block headers

  • logs - Subscribe to contract event logs

  • newPendingTransactions - Subscribe to pending transactions

Request Example

cURL (wscat)
# This method requires WebSocket connection
wscat -c wss://go.getblock.io/<ACCESS-TOKEN>/

> {"jsonrpc":"2.0","method":"eth_subscribe","params":["newheads"],"id":"getblock.io"}

Response Example

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "0x9cef478923ff08bf67fde6c64013158d"
}

Response Parameters

Parameter
Type
Description

subscription

string

Subscription ID

result

object

Event data (varies by subscription type)

Use Cases

  • Real-time block monitoring

  • Live event tracking for dApps

  • Instant transaction notifications

  • Building live dashboards

  • MEV and arbitrage detection

Error Handling

Error Code
Description

-32602

Invalid subscription type or filter

-32603

Internal error

Connection closed

WebSocket disconnected

SDK Integration

Last updated

Was this helpful?