Batch RPC

The JSON-RPC 2.0 specification support batch request natively. Which enable user send several request at the same time. The Client MAY send an Array filled with Request objects, The Server should respond with an Array containing the corresponding Response objects, after all of the batch Request objects have been processed.

For example:

--> [
        {"jsonrpc": "2.0", "method": "sum", "params": [1,2,4], "id": "1"},
        {"jsonrpc": "2.0", "method": "notify_hello", "params": [7]},
        {"jsonrpc": "2.0", "method": "subtract", "params": [42,23], "id": "2"},
        {"foo": "boo"},
        {"jsonrpc": "2.0", "method": "foo.get", "params": {"name": "myself"}, "id": "5"},
        {"jsonrpc": "2.0", "method": "get_data", "id": "9"} 
    ]
<-- [
        {"jsonrpc": "2.0", "result": 7, "id": "1"},
        {"jsonrpc": "2.0", "result": 19, "id": "2"},
        {"jsonrpc": "2.0", "error": {"code": -32600, "message": "Invalid Request"}, "id": null},
        {"jsonrpc": "2.0", "error": {"code": -32601, "message": "Method not found"}, "id": "5"},
        {"jsonrpc": "2.0", "result": ["hello", 5], "id": "9"}
    ]

Conflux's RPC method also support batch request, both HTTP and Websocket.

js-conflux-sdk will enable user easily call RPC batched from v2.0.

Quick start

From js-conflux-sdk v2.0 batch RPC is supported.

One thing to note is execute method will not clear previous added request, so if you add some request later and then call execute method again, all request will send one time. BatchRequest provide one method clear to remove all request previous added.

Batch Send Transaction

To batch send transaction, now developer could use SDK's helper to build a rawTransaction and add it to bacher's request array.

Note: when sending transation there is a max amount limit 2000 for one account.

Batch interact with contract

Contract interaction is also supported.

Last updated

Was this helpful?