[Filter] eth_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: eth_subscribe
Request
- application/json
Body
Default value: eth_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 Number that indicates the error type that occurred. This MUST be an integer.
| code | message | description | |-----|-----|-------| | -32700 | Parse error | invalid JSON was received by the server. An error occurred on the server while parsing the JSON text. | |-32602 | Invalid params | Invalid method parameter(s). |
A String providing a short description of the error. The message SHOULD be limited to a concise single sentence.
A Primitive or Structured value that contains additional information about the error. This may be omitted. The value of this member is defined by the Server (e.g. detailed error information, nested errors etc.).
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": "0x48bb6cb35d6ccab6eb2b4799f794c312"
}