Developers

Caduceus WebSocket Endpoints

8min

WebSocket is a bidirectional communication protocol based on TCP that standardises communication between a client and a server, allowing for both parties to request data from one another. In contrast, a unidirectional protocol like HTTP only allows for the client to request data from the server. The JSON RPC endpoint that you would use to connect to caduceus is an example of a unidirectional protocol using HTTP.

A WebSocket connection between a client and a server can stay open as long as the parties wish it to maintain the connection, allowing for continuous communication. With HTTP, each connection begins when the client makes a request and ends the connection when the request is fulfilled.

WebSockets may be superior for Web3 dApp notifications because they enable real-time notifications for critical events continuously compared to requiring individual requests. So if your D'App needs to monitor the chain and react to certain events then this is the right place to look for.

Caduceus WebSocket Endpoint

For Mainnet the websocket endpoint URL is wss://mainnet.ws.caduceus.foundation

Text


Currently we do not support websockets for the galaxy testnet

You can either embed this in your Web3 provider like ethers.js or use a cli tool like wscat and call it directly from your terminal. Let us show you how you do this:

Using WSCAT on the Terminal

on Mac

First you will need to install wscat. You can do so using npm.

Shell


Then you need to you can call

Shell


Now enter the json payload to indicate the event that you want to listen to a specific event:

Shell


For more information about the eth specification then check out our eth_subscribe documentation



Ethers.js

Ethers provides a websocket provider so that you can listen to your scripts in your javascript or your nodejs application.



JS


You can run this script by doing:

Shell


You need to have ts-node installed and point to the name of the file. In our case we named our file caduceus-websockets.ts.

Remeber to check the full documentation for eth_subscribe here: eth_subscribe