Starts a subscription (on WebSockets / IPC / TCP transports) to a particular event. For every event that matches the subscription a JSON-RPC notification with event details and subscription ID will be sent to a client.
An example notification received by subscribing to newHeads event:
{"jsonrpc":"2.0","method":"eth_subscription","params":{"subscription":"0x416d77337e24399d","result":{"difficulty":"0xd9263f42a87",<...>,
"uncles":[]}}}
You can unsubscribe using eth_unsubscribe RPC method. Subscriptions are also tied to a transport
connection, disconnecting causes all subscriptions to be canceled.
String- Subscription type: one ofnewHeads,logsObject- Subscription type-specific parameters. It must be left empty fornewHeadsand must contain filter object forlogs.
params: [
"logs",
{
"fromBlock": "latest",
"toBlock": "latest"
}
]String- Assigned subscription ID
Request
curl --data '{"method":"eth_subscribe","params":["newHeads",{"fromBlock":"latest","toBlock":"latest"}],"id":1,"jsonrpc":"2.0"}' -H "Content-Type: application/json" -X POST localhost:8545Response
{
"id": 1,
"jsonrpc": "2.0",
"result": "0x416d77337e24399d"
}Unsubscribes from a subscription.
String- Subscription ID
params: ["0x416d77337e24399d"]Boolean- whether the call was successful
Request
curl --data '{"method":"eth_unsubscribe","params":["0x416d77337e24399d"],"id":1,"jsonrpc":"2.0"}' -H "Content-Type: application/json" -X POST localhost:8545Response
{
"id": 1,
"jsonrpc": "2.0",
"result": true
}