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

Supported Methods

All the methods supported by JSON-RPC API are also supported by Websocket API.

Websocket Example

moi.TDU

This method is used to retrieve the Total Digital Utility (TDU) of a specific address. It is a method to get a list of all asset IDs associated with a given address and their total supply.

Parameters:

ParameterTypeDescription
addressHEX (32 Bytes)the address of the sender for which TDU is required.
optionsTesseractOptionsOptions for querying the tesseract.

Returns:

Return TypeDescription
ARRAYA list of asset IDs and their respective total supply.
{
"method": "moi.TDU",
"params": [
{
"address": "0xd5bbbb63252d6cec1263ee5b58732ae9ba0e5b234ce8a333eaf78c83b734d69d",
"options": {
"tesseract_number": -1
}
}
],
"jsonrpc": "2.0",
"id": 1
}

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 newLogs

Parameters Required:

  • Event name
  • Address
  • Start Height
  • End Height
  • Topics

Returns:

  • The Subscription ID (Response)
  • Logs associated with the given address (Emitted response)
Type of topic queries:
ParameterDescription
[] or nilmatches any topic list
[[A]]matches topic A in first position
[[], [B]]matches any topic in first position AND B in second position
[[A], [B]]matches topic A in first position AND B in second position
[[A], [B]], [[C], [D]]matches topic (A OR B) in first position AND (C OR D) in second position
{
"method": "moi.subscribe",
"params": [
"newLogs",
{
"address": "0x5fc0247c18448e91d15542ffb7a0956b6d5f1a19bdd11a36e6a1f7369288f886",
"start_height": 0,
"end_height": 2,
"topics": []
}
],
"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
}