WebSocket Subscriptions
Subscribe to Rome EVM events over WebSocket — eth_subscribe with newHeads and logs, working out of the box with ethers; with viem, use polling.
Rome EVM endpoints support Ethereum WebSocket subscriptions (eth_subscribe / eth_unsubscribe) over wss://. Connect to the same host as the HTTPS RPC, with the wss:// scheme:
wss://<chain>.<network>.romeprotocol.xyz/This is what the ethers WebSocketProvider uses under the hood, so .on('block') and contract.on(event) work out of the box. viem needs one setting, described in the viem section.
Subscription types
newHeads
each new block
block tickers, refreshing balances/nonces, per-block bots, indexers
logs
matching events (by address / topics)
reacting to your contract's events, relayers/bridges, trading bots
newPendingTransactions
—
accepted but never emits (Rome has no public mempool)
ethers (v6)
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 — react to a contract event
const contract = new ethers.Contract(address, abi, provider);
contract.on("Transfer", (from, to, value) => {
console.log("Transfer", from, to, value.toString());
});viem
viem's webSocket transport registers a subscription only when the id is a string. Rome returns a number, so watchBlocks over a plain webSocket transport receives nothing. Pass poll: true and viem polls over the connection instead (checked with watchBlocks), or use ethers for push updates.
Raw JSON-RPC
The subscription id is a JSON number, not a hex string, and the notifications carry the same number. ethers handles this for you. viem's webSocket transport only accepts a string id, so it drops the notifications (see viem). If you write a raw client, compare ids as numbers and pass the number back to eth_unsubscribe.
For logs, pass a filter object as the second param:
Notes
Subscriptions push updates as new blocks are produced (latency is on the order of a block time).
For long-lived connections, handle reconnects in your client — standard for any WebSocket RPC.
Last updated
Was this helpful?