Do WebSockets Need a Ping to Stay Alive with Alchemy?
When using Alchemy’s WebSockets, it’s important to understand how “pings” work for maintaining your connection and ensuring communication with the Alchemy servers.
SDK Heartbeat Ping
Our Alchemy SDK automatically sends a net_version
heartbeat ping to the Alchemy servers every 30 seconds. This is done to maintain the connection and verify the server’s liveness. The great news is that these pings incur zero Compute Units (CUs) comsumption.
📘 For more details on the net_version
method, you can refer to our documentation here.
Do You Need to Send Pings?
You don’t need to manually send pings to keep your WebSocket connection alive. Alchemy servers will periodically send pings to your client to check for liveness, and as long as your client responds to these pings, the connection will remain active.
Final Thoughts
To maintain your WebSocket connection with Alchemy, rely on the SDK’s automatic net_version pings or the pings sent by the server. There’s no need to implement custom pings on your end. Just ensure your client responds to the server’s pings to keep the connection alive!