Skip to main content

eth_subscribe

Ethereum API

Subscribes to specific events on the Ethereum network, such as new blocks, new pending transactions, or changes in the state of an account. When an event occurs, a notification is sent to the client with the corresponding data. To stop receiving notifications, the client can unsubscribe using eth_unsubscribe.

Params

(2)

1. subscriptionType (required)

string

The type of subscription to create. Must be one of the following:

  1. newHeads - New block headers.
  2. logs - Logs matching a filter object.
  3. newPendingTransactions - New pending transactions.
  4. syncing - Changes in syncing status.
Allowed values:
newHeadslogsnewPendingTransactionssyncing

2. filterOptions

(Optional) An object containing filter options specific to the subscription type. Only applicable for the logs subscription type.

address
string

(Optional) A single address or an array of addresses to filter the logs by.

topics
array[string]
required

An array of topics to filter the logs by.

Result

(subscriptionId)

A unique subscription ID that can be used to unsubscribe or identify incoming notifications.

string

Example

Request

await window.ethereum.request({
"method": "eth_subscribe",
"params": [
"newHeads"
]
});

Result

"0x1b84f2cdf29a204b79e450c1939b30c1"

Params

subscriptionType

filterOptions

topics*

Request

await window.ethereum.request({
"method": "eth_subscribe",
"params": [
null,
null
]
});