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.
EVM Chain | Subscribe | Unsubscribe |
---|---|---|
Ethereum | eth_subscribe | eth-unsubscribe |
BSC | eth-subscribe | eth-unsubscribe |
Polygon-PoS | eth-subscribe | eth_unsubscribe |
Arbitrum | eth-subscribe | eth-unsubscribe |
Optimism | eth-subscribe | eth_unsubscribe |
Avalanche | eth-subscribe | eth-unsubscribe |
Base | eth_subscribe | eth_unsubscribe |
Fantom | eth-subscribe | eth-sunsubscribe |
X Layer | eth-subscribe | eth-unsubscribe |
Core | eth-subscribe | eth-unsubscribe |
Mantle | ethsubscribe | eth-unsubscribe |
Artela | eth-subscribe | eth-unsubscribe |
zkSync Era | eth-subscribe | eth-unsubscribe |
Mint | eth-subscribe | eth-unsubscribe |
Chainbase | eth-subscribe | eth-unsubscribe |
Taiko | eth_subscribe | eth_unsubscribe |