Infura now supports WebSockets on Polygon
Introducing Infura Polygon WebSocket: Real-time bidirectional communication on Polygon, empowering developers to create dynamic dapp experiences.
Introducing the Infura Polygon WebSocket: Real-time bidirectional communication on Polygon, empowering developers to create dynamic dapp experiences.
Infura has expanded its WebSocket support to include Polygon, enhancing our existing WebSocket capabilities for Ethereum. This launch brings real-time, bidirectional communication to Polygon developers using Infura and will enable them to create even more immersive and dynamic decentralized applications.
WebSocket is a communication protocol that facilitates two-way, real-time communication between a client - such as a web browser - and a server. Unlike traditional HTTP communication, which follows a request-response model, WebSockets maintain a persistent connection between the client and the server, which allows for ongoing, bidirectional data exchange without the need for repeated requests.
The results are low-latency, real-time communication, making it suitable for applications requiring instant updates or continuous data streaming. Additionally, Infura's Polygon WebSocket solution offers faster performance compared to other available solutions on the market by reducing latency up to 100ms.
Learn more about the Polygon WebSocket on the Infura website.
Supported Features of the Polygon WebSocket
For this launch, we will be supporting two types of request options:
- Stateful subscriptions over WebSockets (wscat -c wss://) which allows users to submit an eth_subscribe request, establishing a bidirectional and persistent connection for real-time data push (long-polling) from the server to the client until intentionally using the eth_unsubscibe method.
- Stateless WebSockets over HTTP (https://) are also supported. A user can subscribe to an event via HTTP and will get one response as HTTP does not establish a persistent connection.
While we support stateless connections over HTTP, we recommend utilizing the stateful subscription over WebSocket as HTTP WebSocket requests may experience silent failures or be limited by load balancing.
Users can create a new stateful subscription over WebSockets to listen to specific events, including:
- Newheads - which emits an event whenever a new header is added to the chain, even during a chain reorganization.
- Logs - which emit logs matching a specified topic filter and are included in newly added blocks.
- Pending transactions - which subscribes to all pending transactions, regardless of the sender, returning their transaction hashes via WebSockets.
Common use cases for the Polygon WebSocket
Track NFT Minting on Polygon: WebSocket provides the ability to track real-time updates on NFT contracts whenever a new NFT is minted. This allows NFT contract owners to stay informed about each instance of NFT minting, enabling them to respond or trigger specific actions based on these events.
Monitor DeFi dapp Market: DeFi dApps can leverage Polygon WebSocket to stay connected with cryptocurrency markets. By subscribing to updates for market trades, orders, and Best Bid Offers (BBO), dApps can receive real-time information about the latest token transfers for a specific address.
Monitor Blockchain and Block Status: Using the Polygon WebSocket's newHeads parameter with eth_subscribe, developers and dApps can receive notifications about each new block added to the blockchain allowing them to stay informed about the current status of the blockchain and monitor the progression of blocks in real-time.
Get started using the Polygon WebSocket on Infura
Infura's support for WebSocket on the Polygon network opens up new possibilities for developers by offering two powerful request options: stateful subscriptions over WebSockets(wss) and stateless WebSockets over HTTP.
With real-time, bidirectional communication, developers are able to track NFT minting, monitor DeFi markets, and stay updated on blockchain and block status, allowing them to create dynamic and immersive decentralized applications.
Refer to this tutorial for step-by-step instructions on how to start building on Polygon with Infura’s Polygon WebSocket offering. In the meantime, if you have any questions or would like to speak to our sales team, click here.