githubEdit

eth_subscribe - Polygon

Example code for the eth_subscribe json-rpc method. Сomplete guide on how to use eth_subscribe json-rpc in GetBlock.io Web3 documentation.

The eth_subscribe method creates a subscription over WebSocket to receive real-time notifications for new blocks, pending transactions, or logs matching specified criteria.

circle-info

This method requires a WebSocket connection.

Parameters

Parameter
Type
Required
Description

subscriptionType

string

Yes

Subscription type: "newHeads", "newPendingTransactions", "logs"

filterObject

object

No

Filter options for log subscriptions

Request

curl --location --request POST 'https://go.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "eth_subscribe",
    "params": ["newHeads"],
    "id": "getblock.io"
}'

Response

{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": "0x9cef478923ff08bf67fde6c64013158d"
}

Response Parameters

Field
Type
Description

jsonrpc

string

JSON-RPC version (2.0)

id

string

Request identifier

result

varies

Subscription ID for receiving notifications

Use Case

The eth_subscribe method is useful for:

  • Real-time block monitoring

  • Event streaming

  • Live transaction tracking

Error Handling

Status Code
Error Message
Cause

403

Forbidden

Missing or invalid ACCESS-TOKEN

-32600

Invalid Request

Malformed request body

-32602

Invalid params

Invalid method parameters

Web3 Integration

Last updated

Was this helpful?