Skip to main content
Lasso supports Ethereum JSON-RPC subscriptions over WebSocket for real-time blockchain events. Use 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:
Response:
The 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:
This example subscribes to Transfer events from USDC on Ethereum. Response:
Subscription Events: As matching logs are emitted, the server pushes events:

Log Filter Options

The logs 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:
Specific event signature across all contracts:
Event from multiple contracts:
Event with indexed parameter filter:
This filters for Transfer events where the second indexed parameter (recipient) matches the specified address.

Unsubscribing

Cancel a subscription using eth_unsubscribe: Request:
Response:
A result of true indicates successful unsubscription. After unsubscribing, no more events will be pushed for that subscription ID.

Full Example

Here’s a complete subscription flow using wscat:

Subscription Lifecycle

Automatic Cleanup

Subscriptions are automatically cleaned up when:
  • The WebSocket connection closes
  • The connection times out (see Connection Lifecycle)
  • An eth_unsubscribe request is received

Multiple Subscriptions

You can create multiple subscriptions on a single WebSocket connection:
Each subscription receives a unique subscription ID and events are tagged with the corresponding ID.

Error Handling

Invalid Subscription Type

Request:
Response:

Invalid Filter Format

Request:
Response:

Unsubscribe Non-Existent Subscription

Request:
Response:
A result of false indicates the subscription ID was not found.

Best Practices

Track Subscription IDs

Always store subscription IDs returned by eth_subscribe to unsubscribe later:

Handle Reconnection

Subscriptions don’t persist across reconnections. Re-subscribe after reconnecting:

Filter Logs Efficiently

Use specific filters to reduce network traffic:

Rate Limiting

Subscriptions count toward your API rate limit. Monitor your usage and adjust filters accordingly.