Configure event notifications
Raylz supports publish and subscribe functionality through JSON-RPC notifications. When enabled, clients can listen for events instead of continuously polling for them.
The notification mechanism allows subscription to specific server events by checking a node's subscription ID against events published in the server. Events that have matching subscription IDs trigger a notification containing relevant data and the subscription ID.
Notifications are only sent for current server events. Events that occurred before enabling this feature will not trigger notifications.
Event notifications are stored in an internal buffer, with a cap of 10,000 notifications by default. When the buffer is reached, the server connection is closed.
Subscriptions require a full-duplex connection, available through WebSocket and IPC server configuration. Subscriptions are removed when the connection closes.
Supported subscriptions
Raylz supports subscriptions to the following events: newHeads
, logs
, newPendingTransactions
, and syncing
.
newHeads
The newHeads
event occurs when new headers are appended to the chain. This event is also triggered by chain reorganizations.
To subscribe to newHeads
events, pass the event as a JSON object for "params"
.
logs
The logs
event applies to new imported blocks. Logs are returned based on criteria from a provided filter.
To subscribe to logs
events, pass the event and a search filter as a JSON object to "params"
.
newPendingTransactions
The newPendingTransactions
event occurs after transactions are added to the pending state. This event is triggered when the transaction hash is returned.
To subscribe to newPendingTransactions
events, pass the event name as a JSON object to "params"
.
syncing
The syncing
event indicates when a node starts or stops synchronization with the server. Notifications can return a Boolean value or an object with progress indicators.
To subscribe to syncing
events, pass the event name as a JSON object to "params"
.
Subscription management
Create subscription
Initiate subscriptions with eth_subscribe
. Pass in the subscription name and other arguments as needed.
When successful, this command returns a subscription ID.
Receive notifications
Notifications can be enabled for all events at once. To receive all event notifications, pass eth_subscribe
and a "difficulty"
value if applicable.
Cancel subscription
Cancel subscriptions with the eth_unsubscribe
method. Pass the method with a valid subscription ID.
When successful, the method returns a Boolean to represent the canceled subscription.
This page is a subsection of JSON-RPC server implementation.
Last updated