OKTC leverages Tendermint Core as its consensus engine and is built on the Cosmos SDK framework. While inheriting Tendermint's event format, OKTC adapts these responses to Ethereum-compatible types to support Web3 websocket functionality via Ethereum's PubSub API. This guide covers WebSocket setup, subscriptions, and supported events.
Getting Started with Websockets
To initiate an Ethereum-compatible WebSocket connection:
- Start the REST server using the
--wsportflag (default port:8546) - Use a WebSocket client like ws to establish a connection
๐ Explore OKTC's developer tools for seamless integration.
Mainnet Websocket Endpoint
Connect to: wss://mainnet.oktc.io/ws (replace with actual OKTC mainnet URL)
Managing Subscriptions
Creating Subscriptions
Use eth_subscribe RPC call with:
- Method:
eth_subscribe Parameters:
- Subscription name (e.g.,
newHeads) - Optional filter criteria
- Subscription name (e.g.,
Example Request:
{
"jsonrpc": "2.0",
"id": 1,
"method": "eth_subscribe",
"params": ["logs", {"address": "0x00..."}]
}Canceling Subscriptions
Use eth_unsubscribe with:
- Method:
eth_unsubscribe - Parameters: Subscription ID
Example Request:
{
"jsonrpc": "2.0",
"id": 1,
"method": "eth_unsubscribe",
"params": ["0xab12..."]
}Supported Subscription Types
1. New Block Headers (newHeads)
Triggers on new chain headers, including reorganizations.
Parameters: None
Example Output:
{
"jsonrpc": "2.0",
"method": "eth_subscription",
"params": {
"subscription": "0xab12...",
"result": {
"number": "0x1b4",
"hash": "0x00...",
"parentHash": "0x00..."
}
}
}2. Logs
Filters and streams contract events.
Parameters:
address: Single or array of contract addressestopics: Event signature filters
Example:
{
"address": ["0x00..."],
"topics": ["0x00..."]
}3. Pending Transactions (newPendingTransactions)
Emits hashes of signed transactions entering mempool.
Parameters: None
Example Output: Transaction hash string
4. Sync Status (syncing)
Tracks node synchronization state.
Parameters: None
Output: Boolean or sync progress object
FAQs
Q: What's the difference between Tendermint and Ethereum WebSocket events?
A: OKTC translates Tendermint's native events into Ethereum-compatible formats for Web3 tooling interoperability.
Q: Can I filter logs by multiple contracts?
A: Yes, pass an array of addresses in the address parameter.
Q: How are chain reorganizations handled?
A: For logs subscriptions, removed logs include "removed": true. For newHeads, new canonical chain headers emit normally.
๐ Need advanced WebSocket configurations? Check OKTC's developer portal.
Best Practices
- Always handle
removedflags in log events during reorgs - Specify precise topic filters to reduce bandwidth
- Implement reconnection logic for stable long-running subscriptions
This implementation combines Cosmos SDK efficiency with Ethereum developer familiarity, enabling seamless dApp integration.