PubSub JSON-RPC API

Methods to subscribe/unsubscribe to events and receive notifications on ZKsync Era.

Clients can subscribe to specific events and receive notifications, thus avoiding the need to poll. ZKsync is fully compatible with Geth's pubsub API, except for the syncing subscription.

The WebSocket URL is wss://mainnet.era.zksync.io/ws

eth_subscribe

Creates a new subscription for events.

Parameters

  1. String - Name of the subscription. Valid names include "newHeads" for new block headers, "logs" for new log entries, and others depending on the client's capabilities.
  2. Object - (Optional) Filter conditions for the subscription, applicable for subscriptions like "logs" where specific event criteria can be set.

Returns

DATA - A subscription ID used to identify and manage the subscription.

Example Request

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "eth_subscribe",
  "params": ["newHeads"]
}

Example Response

{
  "id": 1,
  "jsonrpc": "2.0",
  "result": "0x9cef478923ff08bf67fde6c64013158d"
}

eth_unsubscribe

Cancels an existing subscription.

Parameters

  1. DATA - The ID of the subscription to cancel, as returned by eth_subscribe.

Returns

Boolean - true if the subscription was successfully cancelled, false otherwise.

Example Request

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "eth_unsubscribe",
  "params": ["0x9cef478923ff08bf67fde6c64013158d"]
}

Example Response

{
  "id": 1,
  "jsonrpc": "2.0",
  "result": true
}

Made with ❤️ by the ZKsync Community