> ## 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](https://docs.validationcloud.io/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, newPendingTransactions, syncing). 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. Linea needs the filter object, even if empty: `["logs", {}]`.
* **newPendingTransactions** - Returns the hash of each transaction added to the node's pending pool.
* **syncing** - Notifies when the node starts or stops syncing.

`data - object -` (Optional) - Arguments such as an address, multiple addresses, and topics. Only logs that match the address filter (any one of the listed addresses) and the topic filter are returned.

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

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

## 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](https://docs.validationcloud.io/nodeapi/linea/execution-api/eth_unsubscribe.md).

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

//Example (newHeads)
{
  "jsonrpc": "2.0",
  "method": "eth_subscription",
  "params": {
    "subscription": "0x38",
    "result": {
      "number": "0x1f42af7",
      "hash": "0x97b829b89afd73d5ab7654dff5241457d34c219d89d8dcabfb44496f16264d96",
      "parentHash": "0xfff615bb80f7a2bc19a7ef431f7372ef90dd14decbab70608f28fa0951703943",
      "timestamp": "0x6b115d27",
      "gasLimit": "0x77359400",
      "gasUsed": "0x24b28",
      "baseFeePerGas": "0x7",
      "miner": "0xfd5fb23e06e46347d8724486cdb681507592e237",
      "transactionsRoot": "0x6994022ddcdf14f812f4fbc2e7a398a97d73b66feaccda08bbc1581b49907149",
      "receiptsRoot": "0xe7927e6b86eedc66711c8dcce31341f3421936efd0235f6e59d78cfc3f3e6a51"
    }
  }
}
```

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


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