Is there any schema for RPC and Websocket?

Hey any devs :slight_smile: ,

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.

3 Likes

Thank you for not @ me for this question :smiley:

I don’t know any schema/documentation about that. I always read the code when I need this kind of answers.

3 Likes

I mean any devs from the core team. However, if any devs from the community knows the answer, I would accept it, too :slight_smile:

Me too but I would prefer an easier way :slight_smile:

1 Like

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:

  • RPC: http://host_name:rpc_port/method
    All RPC are POST method with Json body
  • WS: ws://host_name:ws_port/
    WS body request example:
  1. Subscribe New Shard Block
    "request": { "jsonrpc": "1.0", "method": "subcribenewshardblock", "params": [0], "id": 1 }, "subcription": "11", "type": 0

  2. Subscribe Beacon Best State:
    "request": { "jsonrpc": "1.0", "method": "subcribebeaconbeststate", "params": [], "id": 1 }, "subcription": "11", "type": 0 }
    WS now support these popular methods:

  • “subcribenewshardblock”: 1 param is shardID
  • “subcribenewbeaconblock”: 0 param
  • “subcribependingtransaction”: 1 param is transaction hash
  • “subcribeshardbeststate”: 1 param is shardID
  • “subcribebeaconbeststate”: 0 param

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")
}
1 Like

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 :slight_smile: