Websocket API Integration for Blockchain Developers

·

Blockchain technology continues to evolve, and with it, the tools developers use to interact with decentralized networks. One of the most efficient ways to receive real-time data from a blockchain is through WebSocket APIs. This guide dives into how developers can leverage WebSocket functionality on OKTC—optimized for Ethereum-compatible Web3 applications—using standardized event subscriptions that mirror Ethereum’s PubSub API.

Whether you're building a decentralized application (dApp), monitoring smart contract events, or tracking transaction flows, understanding how to connect and subscribe to live blockchain updates is essential.

Understanding OKTC’s WebSocket Architecture

OKTC leverages Tendermint Core as its consensus engine and is built using the Cosmos SDK framework, inheriting their robust event broadcasting system. However, to ensure seamless integration with existing Web3 tooling, OKTC translates these native events into Ethereum-compatible formats via its WebSocket interface.

This means developers familiar with Ethereum’s eth_subscribe mechanism can use the same patterns on OKTC—without needing to learn a new protocol.

To get started, launch the REST server with WebSocket support enabled:

--wsport 8546

By default, the WebSocket port is set to 8546. Once active, you can establish a persistent connection using any standard WebSocket client such as ws or browser-based WebSocket implementations.

👉 Discover how real-time blockchain data can power your next dApp project.

Establishing a Subscription

WebSocket subscriptions on OKTC follow Ethereum’s eth_subscribe RPC method. A successful call returns a unique subscription ID, which you can later use to manage or cancel the stream.

Required Parameters

  1. Subscription name – specifies the type of event to listen for
  2. Optional arguments – filters or configuration depending on the subscription type

Example: Subscribe to New Block Headers

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

Response:

{ "id": 1, "result": "0xabc123..." }

The returned string (0xabc123...) is your subscription ID—keep it for future reference.

Canceling a Subscription

When you no longer need to receive updates, clean up resources by canceling the subscription using eth_unsubscribe.

Parameters

  1. Subscription ID – the identifier returned during creation

Example: Unsubscribe from Events

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

Response:

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

A true response indicates successful cancellation.

Supported Subscription Types

OKTC supports several key subscription types that enable real-time monitoring across different layers of blockchain activity.

newHeads

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

Parameters

None required.

Use Case

Ideal for wallets, explorers, or indexing services that must stay in sync with the latest chain state.

👉 Access live blockchain events with low-latency WebSocket connections.


Logs

Streams logs generated by smart contracts that match specific filter criteria. This is especially useful for tracking ERC-20 transfers, NFT mints, or custom event emissions.

During chain reorganizations:

This ensures accurate state reconstruction even after forks.

Parameters

An optional JSON object containing:

Example: Filter USDT Transfer Events

{
  "id": 3,
  "method": "eth_subscribe",
  "params": [
    "logs",
    {
      "address": "0x94695...bca3",
      "topics": ["0xddf252..."]
    }
  ]
}

This setup captures all USDT transfer events from a known contract address.


newPendingTransactions

Receives transaction hashes as they enter the mempool—before confirmation. Only transactions signed with keys available in the node will be broadcasted.

In case of reorganization, transactions that were previously dropped but re-enter the pending pool will be re-emitted.

Parameters

None.

Use Case

Perfect for MEV bots, arbitrage systems, or services requiring early transaction visibility.


syncing

Monitors synchronization status of the node. Returns either:

Parameters

None.

Example Response During Sync

{
  "jsonrpc": "2.0",
  "method": "eth_subscription",
  "params": {
    "subscription": "0x123",
    "result": {
      "startingBlock": "0x100",
      "currentBlock": "0x1a0",
      "highestBlock": "0x200"
    }
  }
}

Useful for health checks and node monitoring dashboards.


Frequently Asked Questions (FAQ)

Q: Is OKTC’s WebSocket API fully compatible with Ethereum tooling?
A: Yes. OKTC maps Tendermint events into Ethereum-standard JSON-RPC responses, allowing direct use with MetaMask, Ethers.js, Web3.js, and other Web3 libraries without modification.

Q: Can I filter logs by multiple contract addresses?
A: Absolutely. The logs subscription accepts an array under the address field, enabling multi-contract monitoring in a single stream.

Q: What happens during network reorganization?
A: The system ensures consistency by re-sending logs from reverted blocks with "removed": true, while emitting new logs from the correct chain path—critical for accurate event processing.

Q: Are there rate limits on WebSocket connections?
A: While there are no hard rate limits, excessive subscriptions may affect performance. Always unsubscribe when done to free up server resources.

Q: How do I test my WebSocket implementation locally?
A: Run a local OKTC testnet node with --wsport enabled and connect using tools like wscat or write scripts in Node.js/Python to simulate subscriptions.

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


Core Keywords

By aligning with Ethereum’s PubSub standards, OKTC empowers developers to build responsive, event-driven applications with minimal friction. Whether tracking asset movements, verifying contract executions, or maintaining real-time dashboards, the WebSocket API provides a reliable pipeline for live blockchain insights.

👉 Start building with real-time blockchain data today.