eth_subscribe
Subscribes to specific events on the Ethereum network, such as new blocks, or logs. 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.
Parameters
subscriptionType(string)requiredThe type of subscription to create. Must be one of the following: 1. newHeads - New block headers. 2. logs - Logs matching a filter object.
filterOptions(object)(Optional) An object containing filter options specific to the subscription type. Only applicable for the logs subscription type.
Returns
A unique subscription ID that can be used to unsubscribe or identify incoming notifications.
Example request
await provider.request({
method: "eth_subscribe",
params: [
"newHeads",
null
]
});
Example response
{
"id": 1,
"jsonrpc": "2.0",
"result": "0x1b84f2cdf29a204b79e450c1939b30c1"
}