> For the complete documentation index, see [llms.txt](https://docs.main.atgraphite.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.main.atgraphite.com/websocket.md).

# WebSocket

## Connection URL

```
wss://api.main.atgraphite.com/ws
```

Once the socket is open, you can subscribe or unsubscribe from a topic by sending requests.

## Subscribing to new block headers

Sends an update each time a new block is appended to the chain.

#### Sample request

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

```json
{
    "method": "subscribe",
    "params": {
        "topic": "blocks"
    }
}
```

{% endtab %}

{% tab title="Inline" %}

```bash
'{"method":"subscribe","params":{"topic":"blocks"}}'
```

{% endtab %}
{% endtabs %}

#### Request query parameters

| Parameter | Description                  |
| --------- | ---------------------------- |
| method\*  | `subscribe` or `unsubscribe` |

#### Sample response

```json
{
    "method": "subscribe",
    "result": {
        "topic": "blocks"
    },
    "success": true
}
```

#### Sample update response

```json
{
    "topic": "blocks",
    "data": {
        "confirmations": "0",
        "decodedExtraData": {
            "awn": 3899,
            "signature": "0xfa29ec77110e0cc3733326b0d195b96f186854a8f4e16b10f54aef1645aaec0e07410caef3fea4464c968707508c3138772d5bea3753d6b92d2886cc675d2df800",
            "vanity": "0x6d61696e6e65742d76616c696461746f722d362d657500000000000000000000"
        },
        "difficulty": "0x01",
        "epoch": false,
        "extraData": "0x6d61696e6e65742d76616c696461746f722d362d65750000000000000000000000000000000000000f3bfa29ec77110e0cc3733326b0d195b96f186854a8f4e16b10f54aef1645aaec0e07410caef3fea4464c968707508c3138772d5bea3753d6b92d2886cc675d2df800",
        "gasLimit": "0xbebc200",
        "gasUsed": "0x5208",
        "gasUsedPercentage": "0.010500",
        "hash": "0x4b3eef2671c3395d3b2958330af6b9bad57907e196d874147b06bd8b88f449a1",
        "internalTransactionCount": "0",
        "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
        "miner": "0xddca5562cf3914e6815c87746109f478a46a6373",
        "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
        "nonce": "0x0100000000000000",
        "number": "0x22d",
        "parentHash": "0x967e2f106a034bf5df2e1ed85c2a78e359fd4b041be1e749e5f4d0bc8cfa0858",
        "receiptsRoot": "0x962005faf1c6a68f940ece9b33cdb5baf7875b5fa60ba34f1b110adfb2872bc5",
        "reward": "4200000000000000",
        "size": "0x2e4",
        "slashingVote": null,
        "stateRoot": "0x714531b9b07d229abcd934f858c16348773156e364c9f4526192d17f3c209d38",
        "timestamp": "0x6790c7e5",
        "totalDifficulty": "0x022e",
        "transactionCount": "1",
        "transactionFees": "4200000000000000",
        "transactionsRoot": "0x8104e51285600c04a1ea494209851e1fa61578e4d756372499eaf760be8740a2"
    }
}
```

## Subscribing to new pending transactions

Sends an update each time a new transaction is appended to the mempool.

#### Sample request

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

```json
{
    "method": "subscribe",
    "params": {
        "topic": "mempool"
    }
}
```

{% endtab %}

{% tab title="Inline" %}

```bash
'{"method":"subscribe","params":{"topic":"mempool"}}'
```

{% endtab %}
{% endtabs %}

#### Request query parameters

| Parameter | Description                  |
| --------- | ---------------------------- |
| method\*  | `subscribe` or `unsubscribe` |

#### Sample response

```json
{
    "method": "subscribe",
    "result": {
        "topic": "mempool"
    },
    "success": true
}
```

#### Sample update response

```json
{
    "topic": "mempool",
    "data": {
        "from": "0x58af7455c7b23d246b62ccc0b9640ac1d4911761",
        "functionName": null,
        "gasPrice": "0",
        "hash": "0xf8f8ef28a7972aa7bd87d6203decc7c573da5787ccd71a31e52b3a3c47410692",
        "methodId": null,
        "timeStamp": "1737542831",
        "to": "0x12652c6d93fdb6f4f37d48a8687783c782bb0d10",
        "type": "0",
        "value": "0"
    }
}
```

## Subscribing to new confirmed transactions

Sends update with transactions from each new block as soon as it is appended to the chain.

#### Sample request

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

```json
{
    "method": "subscribe",
    "params": {
        "topic": "transactions",
        "from": "0x5b0fda57971f09d3ac8fc4a037930a88174ec8bc",
        "to": "0x0000000000000000000000000000000000001105"
    }
}
```

{% endtab %}

{% tab title="Inline" %}

```bash
'{"method":"subscribe","params":{"topic":"transactions","from":"0x5b0fda57971f09d3ac8fc4a037930a88174ec8bc","to":"0x0000000000000000000000000000000000001105"}}'
```

{% endtab %}
{% endtabs %}

#### Request query parameters

| Parameter | Description                                  |
| --------- | -------------------------------------------- |
| method\*  | `subscribe` or `unsubscribe`                 |
| from      | string with the transaction sender address   |
| to        | string with the transaction receiver address |

**Note:** The `from` and `to` parameters are optional. They can be used together, separately, or not provided at all.

#### Sample response

```json
{
    "method": "subscribe",
    "result": {
        "from": "0x5b0fda57971f09d3ac8fc4a037930a88174ec8bc",
        "to": "0x0000000000000000000000000000000000001105",
        "topic": "transactions"
    },
    "success": true
}
```

#### Sample update response

```json
{
    "data": {
        "blockNumber": "1650870",
        "fee": "26681000000000000",
        "from": "0x5b0fda57971f09d3ac8fc4a037930a88174ec8bc",
        "functionName": "transfer(address _to, uint256 _value)",
        "gasPrice": "200000000000",
        "gasUsed": "133405",
        "hash": "0xed09fd81515f8cf83fbdaa73cdc16a761bcc967d4bd949ab5f7ca1fe69d85ee9",
        "methodId": "0xa9059cbb",
        "timeStamp": "1756461192",
        "to": "0x0000000000000000000000000000000000001105",
        "type": "0",
        "value": "0"
    },
    "topic": "transactions"
}
```
