Websocket API
CONNECT
/v1/wsLast modified: 4 days ago
Documentation for websocket API
Notification
The structure of notification is following in all channels:
{
"channel": "channel_name",
"body": "<object or array>" // depends on channel
}
Subscribe
To receive updates from websocket API send subscribe
request to server.
{
"method": "subscribe",
"body": {
"channel": "<CHANNEL_NAME>",
"filters": {
// pass channel filters
}
}
}
Now 3 channels are supported:
head
- receive information about indexer state. Channel does not have any filters. Subscribe message should looks like:
{
"method": "subscribe",
"body": {
"channel": "head"
}
}
Notification body of responses.State
type will be sent to the channel.
blocks
- receive information about new blocks. Channel does not have any filters. Subscribe message should looks like:
{
"method": "subscribe",
"body": {
"channel": "blocks"
}
}
Notification body of responses.Block
type will be sent to the channel.
gas_price
- receive information about current gas price. Channel does not have any filters. Subscribe message should looks like:
{
"method": "subscribe",
"body": {
"channel": "gas_price"
}
}
Notification body of responses.GasPrice
type will be sent to the channel.
Unsubscribe
To unsubscribe send unsubscribe
message containing one of channel name describing above.
{
"method": "unsubscribe",
"body": {
"channel": "<CHANNEL_NAME>",
}
}
Code example
const WebSocket = require('ws');
const websocketUrl = 'wss://api-mainnet.celenium.io/v1/ws';
const apiKey = '__YOUR__API__KEY__';
const ws = new WebSocket(websocketUrl, {
headers: {
'apiKey': `${apiKey}`,
}
});
// Event: Connection established
ws.on('open', () => {
console.log('Connected to the WebSocket server');
ws.send(JSON.stringify({
method: "subscribe",
body: {
channel: "blocks"
}
}));
});
// Event: Message received from the server
ws.on('message', (data) => {
console.log('Message received:', data.toString());
});
// Event: Connection closed
ws.on('close', () => {
console.log('Connection closed');
});
// Event: Error occurred
ws.on('error', (error) => {
console.error('WebSocket error:', error);
});
Request
None
Request samples
Responses
Success(200)
HTTP Code: 200
Content Type : JSONapplication/json
Data Schema
object {0}
Example
{}
Last modified: 4 days ago