> For the complete documentation index, see [llms.txt](https://docs.rome.builders/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.rome.builders/tr/gelistirici-kilavuzlari/websocket-subscriptions.md).

# WebSocket Abonelikleri

WebSocket üzerinden Rome EVM olaylarına abone olun — newHeads ve logs ile eth\_subscribe, ethers ile kutudan çıktığı gibi çalışır; viem ile polling kullanın.

Rome EVM uç noktaları Ethereum WebSocket aboneliklerini destekler (`eth_subscribe` / `eth_unsubscribe`) üzerinde `wss://`. HTTPS RPC ile aynı ana makineye, şu `wss://` şema:

```
wss://<chain>.<network>.romeprotocol.xyz/
```

Bu, şunun `ethers` `WebSocketProvider` kaputun altında kullandığı şeydir, bu yüzden `.on('block')` ve `contract.on(event)` kutudan çıktığı gibi çalışır. `viem` bir ayara ihtiyaç duyar; bu ayar [viem](#viem) bölümünde açıklanmıştır.

## Abonelik türleri

| Tür                      | Şu durumda tetiklenir:                           | Şunun için kullanın:                                                               |
| ------------------------ | ------------------------------------------------ | ---------------------------------------------------------------------------------- |
| `newHeads`               | her yeni blok                                    | blok sayaçları, bakiyeleri/nonce'ları yenileme, blok başına botlar, dizinleyiciler |
| `logs`                   | eşleşen olaylar (şuna göre: `adres` / `konular`) | sözleşmenizin olaylarına tepki verme, aktarıcılar/köprüler, alım-satım botları     |
| `newPendingTransactions` | —                                                | kabul edilir ama hiç yayınlanmaz (Rome'un genel bir mempool'u yoktur)              |

## ethers (v6)

```javascript
import { ethers } from "ethers";

const provider = new ethers.WebSocketProvider(
  "wss://hadrian.testnet.romeprotocol.xyz/"
);

// newHeads
provider.on("block", (blockNumber) => {
  console.log("new block", blockNumber);
});

// logs — bir sözleşme olayına tepki ver
const contract = new ethers.Contract(address, abi, provider);
contract.on("Transfer", (from, to, value) => {
  console.log("Transfer", from, to, value.toString());
});
```

## viem

`viem`’nin `webSocket` transport, bir aboneliği yalnızca id bir dize olduğunda kaydeder. Rome bir sayı döndürür, bu yüzden `watchBlocks` sıradan bir `webSocket` transport hiçbir şey almaz. Şunu geçin: `poll: true` ve `viem` bunun yerine bağlantı üzerinden yoklar (şununla kontrol edilir: `watchBlocks`), ya da kullanın `ethers` itme güncellemeleri için.

```javascript
import { createPublicClient, webSocket } from "viem";

const client = createPublicClient({
  transport: webSocket("wss://hadrian.testnet.romeprotocol.xyz/"),
});

const unwatch = client.watchBlocks({
  poll: true,
  onBlock: (block) => console.log("new block", block.number),
});

client.watchEvent({
  poll: true,
  address,
  onLogs: (logs) => console.log(logs),
});
```

## Ham JSON-RPC

```json
→ {"jsonrpc":"2.0","id":1,"method":"eth_subscribe","params":["newHeads"]}
← {"jsonrpc":"2.0","id":1,"result":8704545703806774}            // subscription id
← {"jsonrpc":"2.0","method":"eth_subscription","params":{"subscription":8704545703806774,"result":{…block…}}}
```

Abonelik kimliği bir JSON sayısıdır, onaltılık bir dize değil; bildirimler de aynı sayıyı taşır. `ethers` bunu sizin için yönetir. `viem`’nin `webSocket` transport yalnızca bir dize kimliğini kabul eder, bu yüzden bildirimleri atar (bkz. [viem](#viem)). Ham bir istemci yazarsanız, kimlikleri sayılar olarak karşılaştırın ve sayıyı geri gönderin `eth_unsubscribe`.

Şunun için: `logs`, ikinci parametre olarak bir filtre nesnesi geçin:

```json
{"jsonrpc":"2.0","id":1,"method":"eth_subscribe","params":["logs",{"address":"0x…","topics":["0x…"]}]}
```

## Notlar

* Abonelikler, yeni bloklar üretildikçe güncellemeleri iter (gecikme, bir blok süresi mertebesindedir).
* Uzun ömürlü bağlantılar için, yeniden bağlantıları istemcinizde yönetin — bu, herhangi bir WebSocket RPC için standarttır.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.rome.builders/tr/gelistirici-kilavuzlari/websocket-subscriptions.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
