eth_subscribe
The eth_subscribe method allows clients to subscribe 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 the eth_unsubscribe method.
Params
(2)1. subscriptionType (required)
The type of subscription to create. Must be one of:newHeads
: new block headers - logs
: logs matching a filter object - newPendingTransactions
: new pending transactions - syncing
: changes in syncing status
2. filterOptions (required)
An optional object containing filter options specific to the subscription type. Only applicable for 'logs' subscription type.
A single address or an array of addresses to filter the logs by. Optional.
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.
Example
Request
await window.ethereum.request({
"method": "eth_subscribe",
"params": [
"newHeads"
]
});
Result
"0x1b84f2cdf29a204b79e450c1939b30c1"