> For the complete documentation index, see [llms.txt](https://sodex.com/documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sodex.com/documentation/for-developers/api-reference/json-rpc/eth-subscribe.md).

# eth\_subscribe

POST `wss://mainnet-ws.valuechain.xyz`

Creates a subscription over WebSocket for new heads, logs, or pending transactions.

`newHeads` follows `latest`, not `finalized`. New heads arrive about every 2 seconds; `safe` and `finalized` typically lag that head by one slot. See [block tags](/documentation/for-developers/developers/valuechain-evm/differences-from-ethereum.md#consensus-finality).

Use `wss://mainnet-ws.valuechain.xyz` or `wss://testnet-ws.valuechain.xyz`. HTTP returns `notifications not supported`.

## Parameters

| Name           | Type   | Required | Description                                      |
| -------------- | ------ | -------- | ------------------------------------------------ |
| `subscription` | string | Yes      | `newHeads`, `logs`, or `newPendingTransactions`. |
| `options`      | object | No       | For `logs`, an optional filter object.           |

## Result

**Subscription ID** (data): Subscription identifier used with `eth_unsubscribe`. Subsequent messages arrive as JSON-RPC notifications.

## Example

### Response

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "0x1"
}
```

## Code examples

### cURL

```bash
curl --request POST \
  --url wss://mainnet-ws.valuechain.xyz \
  --header 'Content-Type: application/json' \
  --data '{"jsonrpc": "2.0", "id": 1, "method": "eth_subscribe", "params": ["newHeads"]}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({"jsonrpc": "2.0", "id": 1, "method": "eth_subscribe", "params": ["newHeads"]})
};

fetch('wss://mainnet-ws.valuechain.xyz', options)
  .then((res) => res.json())
  .then((res) => console.log(res))
  .catch((err) => console.error(err));
```

### Python

```python
import requests

url = "wss://mainnet-ws.valuechain.xyz"
payload = {
  "jsonrpc": "2.0",
  "id": 1,
  "method": "eth_subscribe",
  "params": [
    "newHeads"
  ]
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)
```
