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:
Parameter | Type | Description |
---|---|---|
address | HEX (32 Bytes) | the address of the sender for which TDU is required. |
options | TesseractOptions | Options for querying the tesseract. |
Returns:
Return Type | Description |
---|---|
ARRAY | A list of asset IDs and their respective total supply. |
- Request
- Response
{
"method": "moi.TDU",
"params": [
{
"address": "0xd5bbbb63252d6cec1263ee5b58732ae9ba0e5b234ce8a333eaf78c83b734d69d",
"options": {
"tesseract_number": -1
}
}
],
"jsonrpc": "2.0",
"id": 1
}
{
"jsonrpc": "2.0",
"id": 1,
"result": [
{
"asset_id": "0x000000000dbea6ee1ef4adf740671f48e3960fcc267aff7cfb647371ea286a71c1be6797",
"amount": "0x130d41"
},
{
"asset_id": "0x000000004cd973c4eb83cdb8870c0de209736270491b7acc99873da1eddced5826c3b548",
"amount": "0xb54"
}
]
}
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)
- Request
- Response
- Emitted Response
{
"method": "moi.subscribe",
"params": [
"newTesseracts"
],
"jsonrpc": "2.0",
"id": 1
}
{
"jsonrpc": "2.0",
"id": 1,
"result": "71e0d774-f4ab-436f-a5b9-1cb87864dd04"
}
{
"jsonrpc": "2.0",
"method": "moi.subscription",
"params": {
"subscription": "71e0d774-f4ab-436f-a5b9-1cb87864dd04",
"result": {
"participants": [
{
"address": "0x0dbea6ee1ef4adf740671f48e3960fcc267aff7cfb647371ea286a71c1be6797",
"height": "0x0",
"transitive_link": "0x0000000000000000000000000000000000000000000000000000000000000000",
"prev_context": "0x0000000000000000000000000000000000000000000000000000000000000000",
"latest_context": "0xbe31cb6851680cc83732381153672ad31a7c81abb1f331c47086ac8312859cfe",
"context_delta": {
"role": 1,
"behavioural_nodes": [
"3WxxDUvWDqwgP4DqrB37xxh3LkSu4ch9CUxPXND4LGWXU3a6fNF1.16Uiu2HAmLg5o1sr2SdSsL8hMNqGuMWUQ9QExhF3vbwZbtxtnbe4p"
],
"random_nodes": [
"3WybyWow6QohGkPN8kN2XXcWwuwBf79k9Jw9XXHcyBbbtepS59CK.16Uiu2HAmTB2RQgWWCq3YbeXgXgDxk1VM4sNf4rRo77ycZwD48EEo"
],
"replaced_nodes": null
},
"state_hash": "0xe8cd9a3327aa6ce8c604d6340b8f4e14ddfa58b4e4d2dade37afbd6e3dca72bb"
},
{
"address": "0x62b8342797343fd95a2b5abe65dd74034bedd6248d91098f759d3d8408004fc3",
"height": "0x1",
"transitive_link": "0xad1e527a51ee016e46ae225c14afc12a3d6f7097aaa0f7877545ea49494d943f",
"prev_context": "0x236901e48bf2b2befcef156cbcf2e073d841658afe6965d4cb88485b93a429ce",
"latest_context": "0x236901e48bf2b2befcef156cbcf2e073d841658afe6965d4cb88485b93a429ce",
"context_delta": {
"role": 0,
"behavioural_nodes": null,
"random_nodes": null,
"replaced_nodes": null
},
"state_hash": "0x8fcf97d9db135a3caf4920bd9e6af0a9e6b0381e5d0438645c2d77b18d682169"
},
{
"address": "0xa6ba9853f131679d00da0f033516a2efe9cd53c3d54e1f9a6e60e9077e9f9384",
"height": "0x1",
"transitive_link": "0xad1e527a51ee016e46ae225c14afc12a3d6f7097aaa0f7877545ea49494d943f",
"prev_context": "0x236901e48bf2b2befcef156cbcf2e073d841658afe6965d4cb88485b93a429ce",
"latest_context": "0x236901e48bf2b2befcef156cbcf2e073d841658afe6965d4cb88485b93a429ce",
"context_delta": {
"role": 2,
"behavioural_nodes": null,
"random_nodes": null,
"replaced_nodes": null
},
"state_hash": "0xe9ee10dd974029b6a25cd1ad6889ce771613a25a2352e7c17410906cacd49a85"
}
],
"interactions_hash": "0xbf9f9335545e833469cd34c01a94e4570fd78f5bd18feefba749f152fb5e1373",
"receipts_hash": "0x55222f0be6549ba32c03bfef2fcb26b3be90da9ff769d5193c32230ef6ca73a0",
"epoch": "0x0",
"time_stamp": "0x65c1e55c",
"operator": "3WzTzaNPQrTGQoUpBVscNX3KkMdEUU4St1PogzAq9TWpkHSJCchV.16Uiu2HAmJ9LenctGU8qP9uu6XhDqjR8jdRFn2YYg951vmVWV4VAv",
"fuel_used": "0x64",
"fuel_limit": "0x3e8",
"consensus_info": {
"evidence_hash": "0xef666baa331326c81b132aacdf24e7efc22d6f7b8d36f2cf1e7d0178e1058628",
"binary_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"identity_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"ics_hash": "0x792ba0ef9e3adf8a0afb8227d269eee536a2fae77767d77b8ebb799f41f81005",
"cluster_id": "DpkGm1ZN3ms45SXDv5VsrdoJzGDjr71JQXMSKc87BGV7",
"ics_signature": "0x",
"ics_vote_set": "BA{11:xxxxxxxxxxx}",
"round": "0x0",
"commit_signature": "0xa429a5ccb68d6e4bd08e043fb01fd447a147a9d8d2f8e024b3c28b2badb8fc80c85339692a84c58f2564a32d99c912b40f35e96ef05565758de60e8a33eb686c114839b8092674638af6b16262ae4dbb3ab8ab17e87789b1c306b466733e2a9a",
"bft_vote_set": "BA{11:x__x_xxxx__}"
},
"seal": "0x0460857c22c10d9de17d17e7408d0df2b4f4236a7a133324d208179d2a6f670d8f820c640509f25b67c1a56a1aeb7a1a8cfa08dd384c0d18cd6710e83f5b82450149d22757f67bae39a584fe7a344e1d15dba19d95f4aacc8f40ac019ff4d89c4e4f",
"hash": "0x79d841f1b6fba3ff272c7b8e227f98e1f3f7ffe2aee60ff42dfc1465c36ef6d7",
"address": "0x62b8342797343fd95a2b5abe65dd74034bedd6248d91098f759d3d8408004fc3",
"ixns": [
{
"type": 3,
"nonce": "0x0",
"sender": "0x62b8342797343fd95a2b5abe65dd74034bedd6248d91098f759d3d8408004fc3",
"receiver": "0x0000000000000000000000000000000000000000000000000000000000000000",
"payer": "0x0000000000000000000000000000000000000000000000000000000000000000",
"transfer_values": null,
"perceived_values": null,
"perceived_proofs": "0x",
"fuel_price": "0x1",
"fuel_limit": "0xc8",
"payload": {
"symbol": "eVgRL",
"supply": "0x130d41",
"dimension": "0x0",
"standard": "0x0",
"is_logical": false,
"is_stateful": false
},
"mode": "0x0",
"compute_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"compute_nodes": null,
"mtq": "0x0",
"trust_nodes": null,
"hash": "0x4f9bfbe0fb0c127dfaf6a124787b714ade0dc75e58a88f892d08bdfa58762bf0",
"signature": "0x01473045022100a4ceba558deadcdb4f6bc48f4c817760f9023ce12b61bdb465165f2b3ecc960902203fdc723ec9948065c234b786b0782d86795a0879074426c526265aa385c9965802",
"ts_hash": "0x79d841f1b6fba3ff272c7b8e227f98e1f3f7ffe2aee60ff42dfc1465c36ef6d7",
"participants": null,
"ix_index": "0x0"
}
]
}
}
}
Subscribing to newTesseractsByAccount
Parameters Required:
- Event name
- Address
Returns:
- The Subscription ID (Response)
- Tesseracts associated with the given address (Emitted response)
- Request
- Response
- Emitted Response
{
"method": "moi.subscribe",
"params": [
"newTesseractsByAccount",
{
"address": "0x62b8342797343fd95a2b5abe65dd74034bedd6248d91098f759d3d8408004fc3"
}
],
"jsonrpc": "2.0",
"id": 1
}
{
"jsonrpc": "2.0",
"id": 1,
"result": "4b53697e-ded1-41c2-8ed0-b8f84ca77e56"
}
{
"jsonrpc": "2.0",
"method": "moi.subscription",
"params": {
"subscription": "4b53697e-ded1-41c2-8ed0-b8f84ca77e56",
"result": {
"participants": [
{
"address": "0x0dbea6ee1ef4adf740671f48e3960fcc267aff7cfb647371ea286a71c1be6797",
"height": "0x0",
"transitive_link": "0x0000000000000000000000000000000000000000000000000000000000000000",
"prev_context": "0x0000000000000000000000000000000000000000000000000000000000000000",
"latest_context": "0xb43417e28f6e31dd0d5ed443772ef113c004af0cfab966d06227936d5a65441e",
"context_delta": {
"role": 1,
"behavioural_nodes": [
"3WyUUeNwX2WsYTqGBwxUg3tWJ2hHifKqG5ZD6L4dcWVFjkjUdwcj.16Uiu2HAm231qfN857HZ8oQbEUh6R1PFvkMcyYisE8cWCYxMiF3uw"
],
"random_nodes": [
"3WxEeH1ioPKucRpBraDLcm38QhCHCTdcAXTxawphsr2GBja4UFeX.16Uiu2HAm33KZSzYSLPVMZH8vJJwTWH77V4LRFgtrK3PZRSiTYNzY"
],
"replaced_nodes": null
},
"state_hash": "0x6fc2b6c49143841b6d619c9dd5f36c200fa54fe95e9f434d26fbb3ae8cee7c6e"
},
{
"address": "0x62b8342797343fd95a2b5abe65dd74034bedd6248d91098f759d3d8408004fc3",
"height": "0x1",
"transitive_link": "0xad1e527a51ee016e46ae225c14afc12a3d6f7097aaa0f7877545ea49494d943f",
"prev_context": "0x236901e48bf2b2befcef156cbcf2e073d841658afe6965d4cb88485b93a429ce",
"latest_context": "0x236901e48bf2b2befcef156cbcf2e073d841658afe6965d4cb88485b93a429ce",
"context_delta": {
"role": 0,
"behavioural_nodes": null,
"random_nodes": null,
"replaced_nodes": null
},
"state_hash": "0x24c3535edb12952a7851eecf5374fc40c202f0e1e1b98d4ec7a3fd49aec85902"
},
{
"address": "0xa6ba9853f131679d00da0f033516a2efe9cd53c3d54e1f9a6e60e9077e9f9384",
"height": "0x1",
"transitive_link": "0xad1e527a51ee016e46ae225c14afc12a3d6f7097aaa0f7877545ea49494d943f",
"prev_context": "0x236901e48bf2b2befcef156cbcf2e073d841658afe6965d4cb88485b93a429ce",
"latest_context": "0x236901e48bf2b2befcef156cbcf2e073d841658afe6965d4cb88485b93a429ce",
"context_delta": {
"role": 2,
"behavioural_nodes": null,
"random_nodes": null,
"replaced_nodes": null
},
"state_hash": "0xfade9d8287096866b632de6834b9b760edd8696d4a394df8eccc4410e1920ac3"
}
],
"interactions_hash": "0x80b4a8c39ca17e5b1692ad627d2c9f29058fac56188387cacb3e4fc8ed4cda62",
"receipts_hash": "0x386ccb644ccc31f8291075ef6aaee8791ee4fe1f0dcca87e3dc1b811a0b36e66",
"epoch": "0x0",
"time_stamp": "0x65c20651",
"operator": "3WzTzaNPQrTGQoUpBVscNX3KkMdEUU4St1PogzAq9TWpkHSJCchV.16Uiu2HAmJ9LenctGU8qP9uu6XhDqjR8jdRFn2YYg951vmVWV4VAv",
"fuel_used": "0x64",
"fuel_limit": "0x3e8",
"consensus_info": {
"evidence_hash": "0xad00870605892eb503fddc36780a7f1fc0b0b26c95cd59f0cc5e53e50dc1718a",
"binary_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"identity_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"ics_hash": "0x7dcc639c62564d4566fba6f8846bbe3fb370675e24f4805c629baf0a88182589",
"cluster_id": "BX84XZm9kQncmPe6CiyMvy3HhPEuiE8FURq16Hzdw6Tt",
"ics_signature": "0x",
"ics_vote_set": "BA{11:xxxxxxxxxxx}",
"round": "0x0",
"commit_signature": "0x94132d29d62cffa5b6f35efa92a115ac73a1078cd2e7578a60893c7c93dfeaa297cf6bcfc5599bcf5c7913a818e808f0117371a134fe23aa6300326bfab9bad2684b833f03606dfe67d75b90803edf3b044a1a8cc1855103422e74ae94f1a2ad",
"bft_vote_set": "BA{11:x__xx__xx__}"
},
"seal": "0x0460b8f1a9e3f2782388c3e616d3210490d584bed468e9f123cee94aea2c244ce6bf04ecee33f0cc6b2359478fe48db42a340499ed06cef9dce89a721df2757573f4a4a30933176ef93a6bce5eb3bb38348c837af191e665bcbc650d345d5b48d89c",
"hash": "0xda673bc9ada5329da2fed45c118a6001b128da4475b2fd10c25774d69fe32c59",
"address": "0x0dbea6ee1ef4adf740671f48e3960fcc267aff7cfb647371ea286a71c1be6797",
"ixns": [
{
"type": 3,
"nonce": "0x0",
"sender": "0x62b8342797343fd95a2b5abe65dd74034bedd6248d91098f759d3d8408004fc3",
"receiver": "0x0000000000000000000000000000000000000000000000000000000000000000",
"payer": "0x0000000000000000000000000000000000000000000000000000000000000000",
"transfer_values": null,
"perceived_values": null,
"perceived_proofs": "0x",
"fuel_price": "0x1",
"fuel_limit": "0xc8",
"payload": {
"symbol": "chsbJ",
"supply": "0x130d41",
"dimension": "0x0",
"standard": "0x0",
"is_logical": false,
"is_stateful": false
},
"mode": "0x0",
"compute_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"compute_nodes": null,
"mtq": "0x0",
"trust_nodes": null,
"hash": "0x819ee05fdca58f7b295621e7f2b4d19b667a8cbc566e9369462b0100febd4be3",
"signature": "0x01463044022002146c137ffab9a8c7dbb5178eb04c8a831cd74b043a89351c8cd8c1c1dfc3fe02205e47b7e16096c7c6d4e0c8a23df57a55dfec6547fd9bccfd814a6ef0ffa25d5402",
"ts_hash": "0xda673bc9ada5329da2fed45c118a6001b128da4475b2fd10c25774d69fe32c59",
"participants": null,
"ix_index": "0x0"
}
]
}
}
}
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:
Parameter | Description |
---|---|
[] or nil | matches 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 |
- Request
- Response
- Emitted Response
{
"method": "moi.subscribe",
"params": [
"newLogs",
{
"address": "0x5fc0247c18448e91d15542ffb7a0956b6d5f1a19bdd11a36e6a1f7369288f886",
"start_height": 0,
"end_height": 2,
"topics": []
}
],
"jsonrpc": "2.0",
"id": 1
}
{
"jsonrpc": "2.0",
"id": 1,
"result": "57d4d7df-7d6a-4689-be14-7d7a59bae8cb"
}
{
"jsonrpc": "2.0",
"method": "moi.subscription",
"params": {
"subscription": "57d4d7df-7d6a-4689-be14-7d7a59bae8cb",
"result": {
"address": "0x5fc0247c18448e91d15542ffb7a0956b6d5f1a19bdd11a36e6a1f7369288f886",
"logic_id": "0x08000012798f8199d5560560fab9673b86cf548e4095affd74f2e8b93095a7c61babec",
"topics": [
"0x223c39e29dff6467fedda09758d91781c5372e091ff86b3af9e310e386562bef",
"0x91f07c7f1215b122f8ac96a1f841293a2a0796395b4e46d2174b4d16f89de12c",
"0x7874d880f84228b8de1435beb3d9c4dd616e61f95e6545bae0f1d0f2eeccffc6"
],
"data": "Da8BBmWWAZUCpgaFB2Ftb3VudAMD6HJlY2VpdmVyBmd0V1wCZa3k/jFAHugyYW99+LUXCXKzeUsXCGOx6Qv2c2VuZGVyBl/AJHwYRI6R0VVC/7eglWttXxoZvdEaNuah9zaSiPiG",
"ix_hash": "0x325bb40b8394042ed02c08e4b002cf8553b7e6e9a78c37d909915f4eb1c690ed",
"ts_hash": "0xaadcfcfcf305b6ea08c4deb2e918c3fb3bedae2a39ebf0a897449d0245e91730",
"participants": [
{
"address": "0x12798f8199d5560560fab9673b86cf548e4095affd74f2e8b93095a7c61babec",
"height": "0x1",
"transitive_link": "0xeb1a692b20a7aa004d7784e52993a3fa6c0bb4c0ff698eebd2198f3fd262ca7d",
"prev_context": "0x9a75ea20041ddbdc3761ea5cbab7799b20f799426535a67abee4e3a736d8b411",
"latest_context": "0x03d6e9313171af891b0b1bd4d538f93bd714a8f6bac30e3d890a84f41a339356",
"context_delta": {
"role": 1,
"behavioural_nodes": null,
"random_nodes": [
"3WzRphh11EWiE45mbDm5bumaByfkkUu9iZ41QSrhxM2HMrJFgopB.16Uiu2HAm2ENyMrr1Hn31fJJAUc1YRZbmgp48FooUW5oXcfWSjnM4"
],
"replaced_nodes": null
},
"state_hash": "0xc35cc6bb765ef94821168e0feb8e4bc55b30b37958b2ce2c80835538529eeb3a"
},
{
"address": "0x5fc0247c18448e91d15542ffb7a0956b6d5f1a19bdd11a36e6a1f7369288f886",
"height": "0x2",
"transitive_link": "0xeb1a692b20a7aa004d7784e52993a3fa6c0bb4c0ff698eebd2198f3fd262ca7d",
"prev_context": "0xbb136a9caef8b06a24e3edc45ced66c397ab7eba6f38737cb1a76dd1cb171865",
"latest_context": "0x0ab5732b33040a6507a01e50e0646ae5d47b29894f360151792259a1c8df6d0d",
"context_delta": {
"role": 0,
"behavioural_nodes": null,
"random_nodes": [
"3WzRphh11EWiE45mbDm5bumaByfkkUu9iZ41QSrhxM2HMrJFgopB.16Uiu2HAm2ENyMrr1Hn31fJJAUc1YRZbmgp48FooUW5oXcfWSjnM4"
],
"replaced_nodes": null
},
"state_hash": "0x39edd7e0065a6361ec3e9254f7a6987b97e489e4deafd2577f45e95786d415fc"
}
]
}
}
}
Subscribing to newPendingInteractions
Parameters Required:
- Event name
Returns:
- The Subscription ID (Response)
- Interaction hash (Emitted response)
- Request
- Response
- Emitted Response
{
"method": "moi.subscribe",
"params": [
"newPendingInteractions"
],
"jsonrpc": "2.0",
"id": 1
}
{
"jsonrpc": "2.0",
"id": 1,
"result": "0b547c81-03f9-460b-bb46-f517d053050b"
}
{
"jsonrpc": "2.0",
"method": "moi.subscription",
"params": {
"subscription": "0b547c81-03f9-460b-bb46-f517d053050b",
"result": "4f9bfbe0fb0c127dfaf6a124787b714ade0dc75e58a88f892d08bdfa58762bf0"
}
}
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
- Request
- Response
{
"method": "moi.unsubscribe",
"params": [
"b9eae598-659e-463e-95b7-a0f265ba4778"
],
"jsonrpc": "2.0",
"id": 1
}
{
"jsonrpc": "2.0",
"id": 1,
"result": "true"
}