[Filter] klay_subscribe
Creates a new subscription to specific events by using either RPC Pub/Sub over WebSockets or filters over HTTP. It allows clients to wait for events instead of polling for them.
The node will return a subscription id for each subscription created. For each event that matches the subscription, a notification with relevant data is sent together with the subscription id. If a connection is closed, all subscriptions created over the connection are removed.
JSONRPC: klay_subscribe
Request
- application/json
Body
Default value: klay_subscribe
Method name
Default value: 1
Request ID, Random or Auto incrementation
Default value: 2.0
JSON-RPC Version (2.0)
Possible values: [newHeads
, logs
]
A notification type: "newHeads" or "logs"
Responses
- 200
Return a subscription id when a subscription is created
- application/json
- Schema
- Example (from schema)
Schema
Default value: 2.0
error
object
A subscription id when a subscription is created. For each event that matches the subscription, a notification with relevant data will be delivered as well.
{
"jsonrpc": "2.0",
"id": 0,
"error": {
"code": -32700,
"message": "Parse error",
"data": "string"
},
"result": "0xbdab16c8e4ae1b9e6930c78359de3e0e"
}
- curl
- python
- nodejs
- java
- CURL
curl -L -X POST 'http://localhost:8551/klay/filter/subscribe' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
--data-raw '{
"method": "klay_subscribe",
"id": 1,
"jsonrpc": "2.0",
"params": [
"newHeads"
]
}'