Skip to main content

Websocket Documentation

Websockets in MOI allow you to create a connection with any operational MOIPod node. To do this, you'll need the IP address and the port number. For instance, to connect to a local server, you may use:

ws://localhost:1600/ws

Setting Up a Subscription

Setting up a subscription involves making a standard JSON RPC call with moi.subscribe as the method and the name of the event as the first parameter. Once the connection is successful, you'll get a subscription ID in return.

Subscribing to newTesseracts

Parameters Required:

  • Event name

Returns:

  • The Subscription ID (Response)
  • New tesseracts generated (Emitted response)
{
"method": "moi.subscribe",
"params": [
"newTesseracts"
],
"jsonrpc": "2.0",
"id": 1
}

Subscribing to newTesseractsByAccount

Parameters Required:

  • Event name
  • Address

Returns:

  • The Subscription ID (Response)
  • Tesseracts associated with the given address (Emitted response)
{
"method": "moi.subscribe",
"params": [
"newTesseractsByAccount",
{
"address": "0x62b8342797343fd95a2b5abe65dd74034bedd6248d91098f759d3d8408004fc3"
}
],
"jsonrpc": "2.0",
"id": 1
}

Subscribing to newPendingInteractions

Parameters Required:

  • Event name

Returns:

  • The Subscription ID (Response)
  • Interaction hash (Emitted response)
{
"method": "moi.subscribe",
"params": [
"newPendingInteractions"
],
"jsonrpc": "2.0",
"id": 1
}

Ending a Subscription

To end a subscription, you will need to make a standard JSON RPC call. This time, you'll use moi.unsubscribe as the method and provide the subscription ID as the first parameter. The system will then return a boolean value, showing whether the unsubscription was successful.

Parameter Required:

  • Subscription ID

Returns:

  • Boolean
{
"method": "moi.unsubscribe",
"params": [
"b9eae598-659e-463e-95b7-a0f265ba4778"
],
"jsonrpc": "2.0",
"id": 1
}