# eth\_subscribe

To subscribe to [real-time data feeds](https://docs.monad.xyz/monad-arch/realtime-data/data-sources)

This method will use `20` [Compute Units](https://docs.validationcloud.io/v1/about/billing).

***

## **Reference:** [**Here**](https://docs.monad.xyz/reference/websockets)

## **Parameters**

1. `subscription type` - **string** - The type of event you want to subscribe to (e.g. newHeads). For Monad, this method supports the following subscription types:

| subscription type | description                                                                                                                                                                     |
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `newHeads`        | Fires a notification each time a new header is appended to the chain, after the block is `Finalized`. Unlike in geth, no reorgs are possible.                                   |
| `logs`            | Returns logs (that match the given filter criteria) in a new block, after the block is `Finalized`. Unlike in geth, no reorgs are possible.                                     |
| `monadNewHeads`   | Same as `newHeads`, but as soon as the block is `Proposed` and the node has a chance to [speculatively execute](https://docs.monad.xyz/monad-arch/realtime-data/spec-realtime). |
| `monadLogs`       | Same as `logs`, but as soon as the block is `Proposed` and the node has a chance to [speculatively execute](https://docs.monad.xyz/monad-arch/realtime-data/spec-realtime).     |

2. `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
params: [
  "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675",
]
```

## 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://app.gitbook.com/o/cJtxpQ7oeewtoIgMb5kv/s/F3uvE671dWWOTAu9svnI/~/changes/221/monad/execution-api/eth_unsubscribe).

```json
// Result
{"jsonrpc":"2.0","result":"0x69caa712b676494a630695cd6f804d52","id":1}

//Example
{
	"jsonrpc": "2.0",
	"method": "eth_subscription",
	"params": {
		"subscription": "0x69caa712b676494a630695cd6f804d52",
		"result": {
			"blockId": "0x692f1864cae90a3d47a9e7f926d87691d89d3af757c2fae915a8c3681dee563a",
			"commitState": "Finalized",
			"hash": "0x8bc5115794ab019e8c1b3bdb64669f6dd02c619d321b6c09797c959ceb533713",
			"parentHash": "0xf1f58b7262ab40558ac89b4406764c7c086aee25ab9b76ca559100fe18a9136d",
			"sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
			"miner": "0x0000000000000000000000000000000000000000",
			"stateRoot": "0xd2632c0fd1bc5d8e4d38942251e89da185225e3a47dddcfa2fab0584aa52a388",
			"transactionsRoot": "0x36d8ca489ef540eff4ac323af6cfccd34788a46f84af6d8eed1f88420a20724d",
			"receiptsRoot": "0x78139fc7a27e2acd52f9bbcb5fd83ba6f1e3d7377f08ceeab773fe239630dcad",
			"logsBloom": "0x00000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000200000000000000000000000000000000000000000002000000000008000000000000000000000000020000000000000000000000000000000000000010000000000000000000000000000000000004000000000000000000400000000000000000000000000000000000000000000000000004000000000000000800000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
			"difficulty": "0x0",
			"number": "0x311c8d9",
			"gasLimit": "0xbebc200",
			"gasUsed": "0x0",
			"timestamp": "0x69244c6e",
			"extraData": "0x0000000000000000000000000000000000000000000000000000000000000000",
			"mixHash": "0xae7a7729bb6db1e5d0a070d3ede99be2ccb3a707c9ad1fbbc4fa6208a9df4832",
			"nonce": "0x0000000000000000",
			"baseFeePerGas": "0x174876e800",
			"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
			"blobGasUsed": "0x0",
			"excessBlobGas": "0x0",
			"parentBeaconBlockRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
			"requestsHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
			"totalDifficulty": "0x0",
			"size": "0x30f"
		}
	}
}
```

{% tabs %}
{% tab title="mainnet" %}

```bash
wscat -c wss:///mainnet.monad.validationcloud.io/v1/wss/<YOUR_API_KEY_HERE>
# wait for connection
{"jsonrpc":  "2.0",  "id":  1,  "method":"eth_subscribe","params":["newHeads"]}
# responses
{"jsonrpc":"2.0","result":"0x4327e562d202d98983a2ee341409f09e","id":1}
```

{% endtab %}

{% tab title="testnet" %}

```bash
wscat -c wss:///testnet.monad.validationcloud.io/v1/wss/<YOUR_API_KEY_HERE>
# wait for connection
{"jsonrpc":  "2.0",  "id":  1,  "method":"eth_subscribe","params":["newHeads"]}
# responses
{"jsonrpc":"2.0","result":"0x4327e562d202d98983a2ee341409f09e","id":1}
```

{% endtab %}
{% endtabs %}
