WebSocket subscriptions
Connect to wss://ethras.org/v1/ethereum/<YOUR_KEY> (Ethereum) and use eth_subscribefor newHeads or logs. Subscriptions report new events, not a persistent history.
New blocks
bashbash
wscat -c 'wss://ethras.org/v1/ethereum/<YOUR_KEY>'> {"id":1,"jsonrpc":"2.0","method":"eth_subscribe","params":["newHeads"]}< {"id":1,"jsonrpc":"2.0","result":"0x9ce59a13059e417087c02d3236a0b1cc"}< {"jsonrpc":"2.0","method":"eth_subscription","params":{"subscription":"0x9ce5…","result":{"number":"0x186da8a", "hash": "0x…"}}}
Contract logs
bashbash
> {"id":2,"jsonrpc":"2.0","method":"eth_subscribe","params":["logs",{"address":"0xdAC17F958D2ee523a2206206994597C13D831ec7"}]}< {"id":2,"jsonrpc":"2.0","result":"0x704b…"}< {"jsonrpc":"2.0","method":"eth_subscription","params":{"subscription":"0x704b…","result":{"address":"0xdac1…","topics":["0xddf2…"],"data":"0x…","blockNumber":"0x186da8a","transactionHash":"0x…","logIndex":"0x6f"}}}
The current execution API includes blockTimestamp in log objects, but field availability can differ across networks and clients. If it is absent, fetch the containing block by blockHash for its timestamp.
Staying connected
- Send a lightweight call (e.g.
eth_chainId) every ~30s as an application-level heartbeat; idle connections may be dropped. - On disconnect, resubscribe from scratch — subscription ids do not survive reconnects.
- After reconnecting, backfill missed events with
eth_getLogsover the gap block range. - To avoid a gap during recovery, establish the new subscription before backfilling from your saved checkpoint, then merge and deduplicate buffered notifications.
- Handle
removed: truewhen a log is reorged out. Logs may be delivered more than once; track block hashes and deduplicate by block hash, transaction hash and log index. - Per-account WebSocket rate-limit violations can close the connection. Reconnect with backoff, then rebuild subscriptions and backfill.
eth_unsubscribewith the subscription id when done.