eth_subscribe to create subscriptions and eth_unsubscribe to cancel them.
Subscription Types
Lasso supports the following subscription types: | Type | Description | |------|-------------|| |newHeads | New block headers as they arrive |
| logs | Log events matching a filter |
Creating Subscriptions
Subscribe to New Block Headers
Request:result field contains the subscription ID. Save this ID to unsubscribe later.
Subscription Events:
As new blocks arrive, the server pushes events:
Subscribe to Logs
Request with filter:Log Filter Options
Thelogs subscription accepts a filter object with:
| Field | Type | Description |
|-------|------|-------------||
| address | string or array | Contract address(es) to filter. Omit for all contracts. |
| topics | array | Event signature and indexed parameters. Use null for wildcards. |
Examples:
All events from a contract:
Unsubscribing
Cancel a subscription usingeth_unsubscribe:
Request:
true indicates successful unsubscription. After unsubscribing, no more events will be pushed for that subscription ID.
Full Example
Here’s a complete subscription flow usingwscat:
Subscription Lifecycle
Automatic Cleanup
Subscriptions are automatically cleaned up when:- The WebSocket connection closes
- The connection times out (see Connection Lifecycle)
- An
eth_unsubscriberequest is received
Multiple Subscriptions
You can create multiple subscriptions on a single WebSocket connection:Error Handling
Invalid Subscription Type
Request:Invalid Filter Format
Request:Unsubscribe Non-Existent Subscription
Request:false indicates the subscription ID was not found.
Best Practices
Track Subscription IDs
Always store subscription IDs returned byeth_subscribe to unsubscribe later: