Hey any devs ,
Is there any schema (up-to-date) document for the responses of RPC and WebSocket calls? If exists, could you share it with us?
Thanks.
Hey any devs ,
Is there any schema (up-to-date) document for the responses of RPC and WebSocket calls? If exists, could you share it with us?
Thanks.
Thank you for not @ me for this question
I don’t know any schema/documentation about that. I always read the code when I need this kind of answers.
I mean any devs from the core team. However, if any devs from the community knows the answer, I would accept it, too
Me too but I would prefer an easier way
Hi, Let’s check this one: https://github.com/incognitochain/incognito-chain/wiki
I believe that the schema for RPC will be available in that link.
For Websocket, hope that @hungngo can advise further.
Hello @abduraman, i think this is the answer you need:
Subscribe New Shard Block
"request": { "jsonrpc": "1.0", "method": "subcribenewshardblock", "params": [0], "id": 1 }, "subcription": "11", "type": 0
Subscribe Beacon Best State:
"request": { "jsonrpc": "1.0", "method": "subcribebeaconbeststate", "params": [], "id": 1 }, "subcription": "11", "type": 0 }
WS now support these popular methods:
This is an example code, written in nodejs which connect to one node via websocket
const WebSocket = require('ws')
const url = process.env.URL || 'ws://localhost:19350/'
const data = {
"request":
{
"jsonrpc": "1.0",
"method": "subcribebeaconbeststate",
"params": [],
"id": 1
},
"subcription": "11",
"type": 0,
}
const socket = new WebSocket(url)
socket.onopen = () => {
socket.send(JSON.stringify(data))
}
socket.onerror = (err) => {
console.log(`websocket error: ${err}`, err)
}
socket.onmessage = e => {
parsedData = JSON.parse(e.data)
console.log(parsedData)
}
socket.onclose = () => {
console.log("Closed Stream")
}
Hey @hungngo,
Thanks for the answer but I’m asking the schema of the responses, not requests. Inferring schemas of the requests from the source code is a little bit easier. So they usually do not create any problem. However, when it comes to the responses, inferring schemas from the source code sometimes becomes a little problematic. It requires trying methods/cases one-by-one. That’s why I asked. If not exists, no problem