Hello! I’m trying to make sense of ICON 2.0 websockets’ notifications and I’m having a hard time figuring them out. So far I have a working prototype where I can connect to the websocket and start receiving the notifications:
- I’m testing with
wss://ctz.solidwallet.io/api/v3/icon_dex/event
(Mainnet). - I followed the documentation found in JSON-RPC - ICON DevPortal
- I’m trying to subscribe to the
Swap
event from Balanced DEx:- Address:
cxa0af3165c08318e988cb30993b3048335b94af6c
- Signature:
Swap(int,Address,Address,Address,Address,Address,int,int,int,int,int,int,int,int,int)
- Match any indexed fields:
[null, null]
- Match any data fields:
[null, null, null, null, null, null, null, null, null, null, null, null, null]
- Address:
Note: I usually request the latest block height and use that height as starting height in the payload.
So, after establishing a connection with the websocket, I send the following text
frame to the websocket (formatted for readability):
{
"height": "0x2cb7f81",
"event": "Swap(int,Address,Address,Address,Address,Address,int,int,int,int,int,int,int,int,int)",
"addr": "cxa0af3165c08318e988cb30993b3048335b94af6c",
"indexed": [null, null],
"data": [null, null, null, null, null, null, null, null, null, null, null, null, null]
}
So, the first notification I got was this one:
{
"events": ["0x4"],
"hash": "0xa82d7793a972bd46550503ff23039f05e04da8df90d69735dfd2f96ab982b84b",
"height": "0x2cb7f88",
"index": "0x1"
}
So, what I understand about the notification:
height
is the height of the block:46890888
hash
is the hash of the block:0xa82d7793a972bd46550503ff23039f05e04da8df90d69735dfd2f96ab982b84b
index
is the index of the transaction inconfirmed_transaction_list
which triggered the event. If we start counting from0
, then it would be the second transaction in the block, which is0xdd22de95b534b0be5b174aada9bb103d0fbc2bb5e0f02b85381b681c6f53ff28
events
is a list of logs indexes where we can find the event that matched our initial query. So, the event I’m interested in would be the 5th log entry, but the event does not match the one I’m expecting:{ "scoreAddress":"cxb0b6f777fba13d62961ad8ce11be7ef6c4b2bcc6", "indexed": [ "BetPlaced(int,int,int)", "0x4563918244f40000", "0x58", "0x0" ], "data":[] }
So, the result doesn’t seem consistent with my first request. Is the payload incorrect? Or did I stumble upon a bug?
I’ve opened an issue as well in goloop project, so I’ll update this post if I get an answer there.
Updated March 3rd, 2022
I got a response in the issue I’ve opened. The following notification:
{
"events": ["0x4"],
"hash": "0xa82d7793a972bd46550503ff23039f05e04da8df90d69735dfd2f96ab982b84b",
"height": "0x2cb7f88",
"index": "0x1"
}
the height
should be interpreted this way:
height
is the next block from which the event occurred. So, if we got46890888
the event is in the previous block46890887
.
Once I get the previous block, I can see the transaction 0x8b790982a10c417759531dfd21c38557ea18f89322935035655c9e8941fa6b85
in the 2nd position and the event I’m looking for is in the 5th position as expected:
{
"scoreAddress":"cxa0af3165c08318e988cb30993b3048335b94af6c",
"indexed":[
"Swap(int,Address,Address,Address,Address,Address,int,int,int,int,int,int,int,int,int)",
"0x1f",
"cx785d504f44b5d2c8dac04c5a1ecd75f18ee57d16"
],
"data":[
"cx785d504f44b5d2c8dac04c5a1ecd75f18ee57d16",
"cx88fd7df7ddff82f7cc735c871dc519838cb235bb",
"cx21e94c08c03daee80c25d8ee3ea22a20786ec231",
"cx21e94c08c03daee80c25d8ee3ea22a20786ec231",
"0x9450c64228750194, 0x33e5860dc2c000000",
"0x5d94c16f57c0e",
"0x38f402673a8b23",
"0x38f402673a8b23",
"0xe8ccf34d9b9dfe01a5d",
"0x51b0dd4c10f894000000",
"0x4deaa2f933ef850a",
"0x278adc63929e602"
]
}
Note: The logs appear in reverse order in the tracker.