API Reference

Using WebSockets in EVM Chain

The WebSocket subscriptions for an EVM blockchain allows subscribing to specific types of events and returns a subscription ID in response. For each event that matches the subscription, a notification with the relevant data is sent along with the subscription ID.

How can I make WebSocket subscriptions for an EVM blockchain more reliable?

After establishing a WebSocket connection to an EVM blockchain node, you may need to send one of the following methods to start/stop receiving push updates for certain state changes in an EVM blockchain network:

  • Subscribe
  • Unsubscribe

What are the types of events that can be subscribed to?

You can specify the type of events you want to subscribe to, which can be one of the following three event types:

  • newHeads: returns a notification each time a new block header is appended to the chain, including those generated from chain reorganizations. In case of a chain reorganization, the subscription emits all new block headers for the new chain. Therefore, a subscription could emit block headers at the same height multiple times.
  • logs: returns logs that are included in the newly added blocks and match the given filter. In case of a chain reorganization, the previously emitted logs on the old chain are re-emitted with the removed property set to true. Logs from transactions in the new chain are emitted. Therefore, a subscription could emit logs for the same transaction multiple times.
    • address - [Optional] An address or an array of addresses. Only logs that are created from these addresses are returned.
    • topics - [Optional] Only records logs that match the specified topics.
  • newPendingTransactions: returns hashes for all transactions that are added to the pending state and signed with keys available in the node (a hash for each transaction). In case of a chain reorganization, some transactions that were originally on the canonical chain may be excluded from the new canonical chain because they are included in other chains. In this case, these transactions are added to the pending state again. Therefore, a subscription can emit logs for the same transaction multiple times.

❗️

Attention:

The Base chain does not support subscribing to new pending transactions.