> ## 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). 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": "0x1742b836bd6acb3f996e17f4b5b3bd172d97a93b"}]
```

## 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/elysium/execution-api/eth_unsubscribe.md).

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

//Example (newHeads)
{
  "jsonrpc": "2.0",
  "method": "eth_subscription",
  "params": {
    "subscription": "0x4e9adcdf37eff2ba0fecfd51481e8305",
    "result": {
      "number": "0x84e617",
      "hash": "0xafa24321c9d8154c5aa636aecf9e6a9d2110fa1ee0083337649ee7e63ea40e87",
      "parentHash": "0xdba001e60884e59a33a11c2b68730127c3b4fa7bf82546db1d3dca1e1ba2d69b",
      "timestamp": "0x6b00340a",
      "gasLimit": "0x4000000000000",
      "gasUsed": "0x4434f",
      "baseFeePerGas": "0x1dcfaef0",
      "miner": "0xa4b000000000000000000073657175656e636572",
      "transactionsRoot": "0xdf9be46e8f4a760c0fb8cef5bd5cfe6823363d58e5006012579d9380fc48967a",
      "receiptsRoot": "0x0a8ef595af4b2aafa302071c3da34eda9b6dd81d3b051b7ea4c1225c97171cc4"
    }
  }
}
```

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

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


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