Ethereum API
Multichain API
eth_subscribe
Summary: Subscribes to specific Ethereum events, returning a subscription ID used to receive notifications.
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
enumThe type of subscription to create. Must be one of the following:
1. newHeads
- New block headers.
2. logs
- Logs matching a filter object.
Enum:
"newHeads"
"logs"
filterOptions
object(Optional) An object containing filter options specific to the subscription type. Only applicable for the logs
subscription type.
Returns
subscriptionId
stringA unique subscription ID that can be used to unsubscribe or identify incoming notifications.
Customize request
Parameter
Value
Connect your MetaMask wallet to run requests successfully.
Request
await window.ethereum.request({
"method": "eth_subscribe",
"params": [
"newHeads"
],
});
Example response
"0x1b84f2cdf29a204b79e450c1939b30c1"