Updated on 2023-12-15 GMT+08:00

eth_subscribe

Introduction

This API creates a new subscription for particular events. The node returns a subscription ID. For each event that matches the subscription, a notification with relevant data is sent together with the subscription ID. It consumes 10 CUs. In the dedicated edition, the throughput is 1000 per second for 8 vCPUs and 32 GB memory and 1000 per second for 16 vCPUs and 64 GB memory.

Parameter Description

Parameter

Type

Description

Event type

String

The type of event to listen to.

Optional parameters

String

Optional parameters to include to describe the type of event to listen to (e.g. newHeads, newPendingTransactions, logs).

Return Value

While the subscription is active, you will receive events formatted as an object described below:

Event Object:
  • jsonrpc: always 2.0.
  • method: always eth_subscription.
  • params: an object with the following fields:
    • subscription: the subscription ID returned by the API that creates this subscription. This ID will be attached to all received events and can also be used to cancel the subscription using eth_unsubscribe.
    • result: an object whose contents vary depending on the event type.

Request

wscat -c wss://your-http-endpoint/v1/<API-KEY> -x '{"jsonrpc":"2.0", "id": 1, "method": "eth_subscribe", "params": ["logs"]}'