> ## Documentation Index
> Fetch the complete documentation index at: https://docs.validationcloud.io/llms.txt
> Use this file to discover all available pages before exploring further.

# eth_subscribe

Subscribes to real-time events over WebSocket and returns a subscription ID that is attached to every notification.

This method will use `20` [Compute Units](/nodeapi/about/billing.md) and each notification delivered on the subscription will use `10` Compute Units regardless of size.

***

## **Reference:** [**Here**](https://ethereum.org/en/developers/tutorials/using-websockets/#eth-subscribe)

## **Parameters**

`subscription name` - **string** - The type of event you want to subscribe to (newHeads, logs). This method supports the following subscription types:

* **newHeads** - Fires a notification each time a new header is appended to the chain, including chain reorganizations.
* **logs** - Returns logs that are included in new imported blocks and match the given filter criteria.

`data - object -` (Optional) - Arguments such as an address, multiple addresses, and topics. Note, only logs that are created from these addresses or match the specified topics will return logs.

```json theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
// newHeads
params: ["newHeads"]

// logs from one contract
params: ["logs", {"address": "0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb"}]
```

## Returns

`result - string` - Hex encoded subscription ID. This ID will be attached to all received events and can also be used to cancel the subscription using [eth\_unsubscribe](/nodeapi/plasma/execution-api/eth_unsubscribe.md).

```json theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
// Result
{"id":1,"result":"0x2aac376f7b5415331eac766221de82e6","jsonrpc":"2.0"}

//Example (newHeads)
{
  "jsonrpc": "2.0",
  "method": "eth_subscription",
  "params": {
    "subscription": "0x2aac376f7b5415331eac766221de82e6",
    "result": {
      "number": "0x2214c02",
      "hash": "0x32965e6b8f06cefb9ac7b0ee315de10ba1a45e1314ecec156e1621addfba75b3",
      "parentHash": "0x7d74edc7b642ce9292ae29f4032eb2db2f878d22a08b91cf3011079442b7eaec",
      "timestamp": "0x6ada1854",
      "gasLimit": "0x2255100",
      "gasUsed": "0x198d7a",
      "baseFeePerGas": "0x9",
      "miner": "0x000000000000000000000000000000000a11b005",
      "transactionsRoot": "0x65a40af9ed662df464d30a5455e6ffa47913780c93a9105d34af1e96ccf5574d",
      "receiptsRoot": "0x4863c5b0791e76fb5c7f69c412f5736e0f079d6db25ab22e39bab181175443a2"
    }
  }
}
```

```bash title="mainnet" theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
wscat -c wss://mainnet.plasma.validationcloud.io/v1/wss/<YOUR_API_KEY_HERE>
{"jsonrpc":  "2.0",  "id":  1,  "method":"eth_subscribe","params":["newHeads"]}
{"jsonrpc":"2.0","result":"0x2aac376f7b5415331eac766221de82e6","id":1}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.