Websocket API for OKTC: Real-Time Blockchain Data Integration

·

Blockchain technology has evolved rapidly, and real-time data access is now a cornerstone for decentralized applications (dApps), analytics platforms, and trading systems. The OKT Chain (OKTC), leveraging the robust Cosmos SDK framework and Tendermint Core consensus engine, offers native Web3 compatibility through its WebSocket API. This enables developers to seamlessly integrate real-time blockchain events into their applications using familiar Ethereum-style pub/sub patterns.

By transforming Tendermint-generated events into Ethereum-compatible formats, OKTC bridges the gap between high-performance consensus mechanisms and widely adopted developer tooling. Whether you're building a wallet, block explorer, or DeFi dashboard, understanding how to use the OKTC WebSocket API is essential.


Establishing a WebSocket Connection

To begin streaming real-time blockchain data from OKTC, you must first establish a WebSocket connection. This is done by initializing the REST server with the --wsport flag. By default, the WebSocket port is set to 8546.

oktc start --wsport 8546

Once the node is running, you can connect using any standard WebSocket client such as ws, wscat, or browser-based clients. The endpoint follows this format:

ws://<your-node-host>:8546

For public access points or production environments, always ensure secure connections (wss://) and proper rate limiting to maintain reliability.

👉 Discover how to connect to real-time blockchain data in seconds


Creating a Subscription

Subscriptions are created using the eth_subscribe RPC method—a familiar pattern for Ethereum developers. This method takes two parameters:

Parameters

  1. Subscription name – Specifies the type of event to listen for.
  2. Optional arguments – Filter criteria depending on the subscription type.

Upon successful registration, the API returns a unique subscription ID, which you’ll use later to cancel or manage the stream.

Example Request

{
  "id": 1,
  "method": "eth_subscribe",
  "params": ["newHeads"]
}

Example Response

{ "id": 1, "result": "0x1a2b3c4d" }

This ID (0x1a2b3c4d) now identifies your active stream. All subsequent notifications will include it for correlation.


Canceling a Subscription

When you no longer need to receive updates, you can terminate the subscription gracefully using eth_unsubscribe.

Parameters

  1. Subscription ID – The string returned during subscription creation.

The method returns a boolean: true if successfully canceled, false otherwise.

Example Request

{
  "id": 2,
  "method": "eth_unsubscribe",
  "params": ["0x1a2b3c4d"]
}

Example Response

{ "id": 2, "result": true }

Proper lifecycle management of subscriptions helps reduce server load and improves application efficiency.


Supported Subscription Types

OKTC supports several key subscription types that mirror Ethereum’s PubSub API, enabling interoperability and ease of migration.

newHeads

Triggers a notification every time a new block header is added to the blockchain—even during chain reorganizations.

Parameters

Use Case

Ideal for dApps that require immediate awareness of chain updates, such as arbitrage bots or cross-chain bridges.

Example Notification

{
  "jsonrpc": "2.0",
  "method": "eth_subscription",
  "params": {
    "subscription": "0x1a2b3c4d",
    "result": {
      "number": "0x1b4",
      "hash": "0xabc123...",
      "parentHash": "0xdef456...",
      "timestamp": "0x62a56f3e"
    }
  }
}

Logs

Streams logs from smart contracts that match specific filter criteria. This is particularly useful for tracking token transfers, swaps, or contract state changes.

Parameters

An optional filter object containing:

Behavior During Reorgs

In case of chain reorganization:

This ensures clients can maintain accurate state even during forks.

Example Request

{
  "id": 3,
  "method": "eth_subscribe",
  "params": [
    "logs",
    {
      "address": "0x742d35Cc6634C0532925a3b8D4C80cD7E9888956",
      "topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]
    }
  ]
}

👉 Start receiving real-time smart contract events today


newPendingTransactions

Receives transaction hashes as they enter the mempool—before confirmation. This is critical for front-running detection, MEV strategies, or instant transaction monitoring.

Parameters

Reorg Handling

If a transaction previously confirmed gets rolled back due to a reorganization, it may reappear in the pending stream.

Example Notification

{
  "jsonrpc": "2.0",
  "method": "eth_subscription",
  "params": {
    "subscription": "0x5e6f7g8h",
    "result": "0xabc123...def456"
  }
}

syncing

Monitors synchronization status of the node. Useful for dashboards or health checks.

Parameters

Response Types

Example Sync Object

{
  "startingBlock": "0x100",
  "currentBlock": "0x1b4",
  "highestBlock": "0x2c0"
}

Frequently Asked Questions (FAQ)

Q: Is the OKTC WebSocket API compatible with Ethereum tools?
A: Yes. It implements Ethereum’s eth_subscribe and eth_unsubscribe methods, making it compatible with most Web3 libraries like Web3.js and Ethers.js.

Q: Can I filter logs by multiple contract addresses?
A: Absolutely. You can pass an array of addresses in the logs subscription filter to monitor multiple contracts simultaneously.

Q: How does the API handle network reorganizations?
A: During reorgs, outdated logs are resent with "removed": true, while new valid logs are emitted normally—ensuring consistent state tracking.

Q: What ports does the WebSocket service use?
A: The default port is 8546. You can customize it using the --wsport flag when starting the node.

Q: Are there rate limits on subscriptions?
A: Public nodes may enforce rate limiting. For uninterrupted access, run your own full node or use a dedicated RPC provider.

Q: Can I receive full transaction objects instead of just hashes?
A: The newPendingTransactions feed only sends hashes. To get full details, use eth_getTransactionByHash with each received hash.


Final Thoughts

The OKTC WebSocket API empowers developers with real-time access to blockchain events in a format that’s both performant and developer-friendly. By combining the speed and scalability of Tendermint with Ethereum-compatible interfaces, OKTC lowers the barrier to entry for building responsive, event-driven applications.

Whether you're tracking new blocks, parsing contract logs, or monitoring pending transactions, this API provides the tools you need for timely and accurate data delivery.

👉 Unlock real-time blockchain insights with seamless WebSocket integration