返回介绍

The parity_pubsub Module

发布于 2023-06-28 21:14:12 字数 2461 浏览 0 评论 0 收藏 0

JSON-RPC methods

JSON-RPC API Reference

parity_subscribe

Starts a subscription (on WebSockets / IPC / TCP transports) to results of calling some other RPC method. For every change in returned value of that RPC call a JSON-RPC notification with result and subscription ID will be sent to a client.

Below examples use wscat, a simple command line WebSockets client. Find out how to install and use it by visiting wscat GitHub repository.

An example notification received by subscribing to eth_getBalance RPC method:

{"jsonrpc":"2.0","method":"parity_subscription","params":{"subscription":"0x416d77337e24399d","result":["0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826"]}}

You can unsubscribe using parity_unsubscribe RPC method. Subscriptions are also tied to a transport connection, disconnecting causes all subscriptions to be canceled.

Parameters

  1. String - RPC method name
  2. Array - Parameters passed to RPC method. (Optional, defaults to no parameters)
params: [
  "eth_getBalance",
  [
    "0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826",
    "latest"
  ]
]

Returns

  • String - Assigned subscription ID

Example

Request

wscat -c localhost:8546
>{"method":"parity_subscribe","params":["eth_getBalance",["0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826","latest"]],"id":1,"jsonrpc":"2.0"}

Response

{
  "id": 1,
  "jsonrpc": "2.0",
  "result": "0x416d77337e24399d"
}

parity_unsubscribe

Unsubscribes from a subscription.

Parameters

  1. String - Subscription ID
params: ["0x416d77337e24399d"]

Returns

  • Boolean - whether the call was successful

Example

Request

wscat -c localhost:8546
>{"method":"parity_unsubscribe","params":["0x416d77337e24399d"],"id":1,"jsonrpc":"2.0"}

Response

{
  "id": 1,
  "jsonrpc": "2.0",
  "result": true
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文