WebSockets
The WebSockets (WSS) communication protocol enables two-way communication between a client and a server over a single TCP connection. The communication protocol maintains a network connection between the two parties, allowing for real-time, low-latency communication. WebSockets allow for ongoing, bidirectional communication unlike HTTP, which is a request-response protocol.
WebSockets allow you to create stateful subscriptions, which is a type of subscription where the server maintains a record of the client's subscription state. This means that the server remembers what data the client has requested and sent previously, and only sends new data that has changed or meets the client's subscription criteria.
You can create stateful subscriptions over WebSockets to subscribe to specific events on the blockchain. The following subscription types are available using the
eth_subscribe
JSON-RPC API:- The
newHeads
subscription type emits an event when a new header (block) is added to the chain, including during a chain reorganization. - The
logs
subscription type emits logs that match a specified topic filter and are included in newly added blocks.
We strongly recommend specifying a filter when subscribing to the
logs
subscription type.- The
newPendingTransactions
subscription type subscribes to all pending transactions via WebSockets (regardless if you sent them or not), and returns their transaction hashes. This subscription type is currently only available on Ethereum, with support for Polygon coming soon.
For information about how to use the subscription methods to subscribe to events, see the
eth_subscribe
JSON-RPC method, or see the following tutorials:The following networks support subscriptions over WebSockets:
- Ethereum
- Polygon
WebSocket support is currently in private beta for the Polygon network, and is only available for stateful subscriptions.
Create stateful subscriptions over WebSockets to listen to specific events. Example use cases include:
- Listen when a new NFT is minted by an NFT minting smart contract, this enables your application to update its count of minted NFTs.
- Listen to a smart contract for the latest token price so that price can be reflected immediately on the application to end users.
- Receive updates for cryptocurrency market trades, orders, and Best Bid Offers (BBO).
- Receive the latest token transfers for an address.
- Receive notifications about each new block added to the blockchain.
Subscriptions over WebSockets are currently free on Ethereum. However, please note subscriptions over WebSockets on Polygon are not free and will be counted as part of your daily request limits.
We may change our pricing model, and implement some limitations on subscriptions over WebSockets on Ethereum and Polygon in the future.
Before implementing any changes, we'll give customers advanced notification, so they can consider the best option for their needs.
Last modified 1mo ago