eth_subscribe
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:
newHeads
- New block headers.logs
- Logs matching a filter object.newPendingTransactions
- New pending transactions.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]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"