OKTC leverages Tendermint Core as its consensus engine and is built using the Cosmos SDK framework. While this provides a robust foundation, OKTC also ensures compatibility with Ethereum's Web3 standards—specifically for websocket communications via the Ethereum PubSub API. This requires converting Tendermint responses into Ethereum-compatible data types.
Getting Started with Websockets
To initiate a connection with the Ethereum websocket, use the --wsport flag when starting the REST server (default port: 8546).
Example:
rest-server --wsport 8546Once the server is running, you can establish a websocket subscription using clients like ws or similar tools.
Websocket URLs
Mainnet Endpoint
wss://mainnet.oktc.io/websocket
Managing Subscriptions
Creating a Subscription
Use the RPC method eth_subscribe with the subscription name and optional arguments.
Parameters:
- Subscription Name (e.g.,
newHeads,logs). - Optional Arguments (e.g., filter criteria for logs).
Example Request:
{
"method": "eth_subscribe",
"params": ["newHeads"]
}Response: Returns a unique subscription ID.
Canceling a Subscription
Use the RPC method eth_unsubscribe with the subscription ID.
Parameters:
- Subscription ID (returned during creation).
Example Request:
{
"method": "eth_unsubscribe",
"params": ["0x9b13452..."]
}Response: Returns true if canceled successfully.
Supported Subscription Types
1. newHeads
Notifies when a new block header is added to the chain (includes reorganizations).
Parameters: None.
Example Output:
{
"header": { ... },
"removed": false
}2. logs
Emits logs from new blocks matching specified filters. Resends logs from orphaned blocks with removed: true.
Parameters:
- address (string or array): Filter by contract address(es).
- topics (array): Filter by log topics.
Example Request:
{
"method": "eth_subscribe",
"params": ["logs", { "address": "0x123...", "topics": ["0xaabb..."] }]
}3. newPendingTransactions
Returns hashes of signed transactions added to the pending state.
Parameters: None.
Example Output:
"0x5e9abc92..."4. syncing
Indicates synchronization status (boolean or progress object).
Example Output:
{
"syncing": true,
"currentBlock": "0x1234",
"highestBlock": "0x5678"
}FAQ
Q1: How do I troubleshoot a failed subscription?
A: Verify the websocket URL and port. Check if the subscription parameters match the supported formats.
Q2: Can I subscribe to multiple events simultaneously?
A: Yes, each subscription requires a separate eth_subscribe call.
Q3: Why are logs duplicated after a reorganization?
A: The protocol resends logs from orphaned blocks with removed: true and emits new chain logs.
👉 Explore advanced websocket configurations for real-time data handling.
Key Terms: OKTC websocket, Ethereum PubSub API, Tendermint events, eth_subscribe, blockchain synchronization, real-time logs, pending transactions.