Blockchain technology continues to evolve at a rapid pace, and real-time data access has become essential for developers building decentralized applications (dApps), monitoring tools, and trading platforms. The Websocket API plays a critical role in enabling instant, bidirectional communication between clients and blockchain nodes. This guide explores how the Websocket API works within the OKTC ecosystem—designed with full Web3 compatibility—and how developers can leverage Ethereum-style event subscriptions over websocket connections.
Whether you're tracking new block headers, monitoring smart contract logs, or watching pending transactions, understanding the Websocket API is key to building responsive and efficient blockchain integrations.
👉 Discover how real-time blockchain data can power your next dApp development project.
Understanding OKTC's Websocket Architecture
OKTC is built on the Cosmos SDK and uses Tendermint Core as its consensus engine. While these frameworks provide robust performance and scalability, OKTC extends their capabilities by implementing native Ethereum Web3 compatibility—including support for the Ethereum PubSub API via WebSockets.
This means that despite being part of the Cosmos ecosystem, OKTC seamlessly translates Tendermint-generated events into Ethereum-compatible formats. As a result, developers familiar with Ethereum’s JSON-RPC over WebSockets can use the same tools, libraries, and patterns when interacting with OKTC.
The core mechanism behind this interoperability lies in the translation layer that maps Tendermint ABCI events into Ethereum-standard eth_subscribe responses. This allows developers to use existing Ethereum tooling—such as web3.js or ethers.js—with minimal configuration changes.
To enable Websocket connectivity, start the REST server with the --wsport flag:
okchaind rest-server --wsport 8546By default, the Websocket server listens on port 8546, aligning with Ethereum’s standard wss:// endpoints for consistency.
Establishing a Websocket Subscription
Subscriptions are created using the eth_subscribe RPC method—a familiar interface for Ethereum developers. Upon successful connection, the node returns a unique subscription ID, which can later be used to cancel the subscription.
Required Parameters
- Subscription name – Specifies the type of event to listen for.
- Optional arguments – Additional filters depending on the subscription type.
Once subscribed, the client receives real-time notifications without needing to poll the network repeatedly—reducing latency and server load.
Example: Connecting via WebSocket Client
You can use any standard WebSocket client to connect. For example, using the ws CLI tool:
ws wss://your-oktc-node:8546
> {"id": 1, "method": "eth_subscribe", "params": ["newHeads"]}
< {"jsonrpc":"2.0","result":"0xdf8f76f7c23235b3d9d8e7b8a6e9c0b1","id":1}Now, every time a new block header is appended to the chain, your client will receive a push notification.
👉 See how easy it is to integrate live blockchain updates into your application.
Supported Subscription Types
OKTC supports several subscription types that mirror those found in Ethereum, ensuring compatibility and ease of migration.
newHeads
Triggers a notification whenever a new block header is added to the blockchain—even during chain reorganizations. This is ideal for applications requiring up-to-the-second block confirmation, such as explorers or staking dashboards.
Parameters
- None
Use Case Example
A block explorer uses newHeads to instantly detect new blocks and update its UI in real time.
Logs
Streams logs generated by smart contracts that match specific filter criteria. This includes logs from newly imported blocks and handles chain reorganizations gracefully.
During a reorg:
- Logs from removed blocks are resent with
"removed": true. - Logs from newly confirmed transactions are emitted normally.
This ensures your application maintains accurate state tracking even during network instability.
Parameters
Filter object (optional):
address: Single address or array of addresses to filter logs from.topics: Array of topic hashes to match log entries (e.g., specific event signatures).
Practical Scenario
A DeFi analytics platform subscribes to Logs with filters set to track Swap events from a specific AMM router contract across multiple pools.
newPendingTransactions
Receives transaction hashes of all transactions entering the pending state—i.e., transactions broadcasted but not yet included in a block. These are typically transactions signed by accounts managed by the node.
In the event of a chain reorganization, transactions that were previously dropped but re-enter the mempool will be re-emitted.
Parameters
- None
Ideal For
- Mempool analyzers
- Front-running detection systems
- Wallet backends needing immediate user feedback after transaction broadcast
syncing
Monitors synchronization status of the node. Returns either:
true— Node has started syncing with the network.false— Node is fully synchronized.- An object with sync progress details (e.g., current block, highest block).
Parameters
- None
Why It Matters
Crucial for infrastructure providers and node operators who need to verify when a node is ready to serve reliable data or validate transactions.
Frequently Asked Questions (FAQ)
Q: Is OKTC's Websocket API compatible with Ethereum tooling?
A: Yes. OKTC fully supports Ethereum’s eth_subscribe standard via WebSockets, allowing seamless integration with web3.js, ethers.js, and other Ethereum development libraries.
Q: Can I filter logs by multiple contract addresses?
A: Absolutely. You can pass an array of contract addresses in the address field of the filter object when subscribing to logs.
Q: How does the API handle chain reorganizations?
A: During reorgs, the system resends affected logs with "removed": true and emits new logs from the updated chain, ensuring consistent and accurate event tracking.
Q: What port does the Websocket server run on by default?
A: The default Websocket port is 8546. You can change it using the --wsport flag when starting the REST server.
Q: Do I need special permissions to create subscriptions?
A: No authentication or special permissions are required. As long as you have access to the node endpoint, you can establish subscriptions.
Q: Are there rate limits on Websocket connections?
A: While there are no hardcoded rate limits, excessive connection attempts may be throttled based on node configuration and resource availability.
👉 Get started today with real-time blockchain data streaming through OKX’s powerful infrastructure.
Core Keywords for SEO Optimization
- Websocket API
- blockchain real-time data
- Ethereum PubSub API
- event subscription
- smart contract logs
- pending transactions
- chain reorganization handling
- dApp development
These keywords have been naturally integrated throughout this article to enhance search visibility while maintaining readability and technical accuracy.
By leveraging OKTC’s Websocket API, developers gain access to a robust, low-latency stream of blockchain events—enabling responsive user experiences and advanced monitoring capabilities. Whether you're building a wallet, exchange interface, or analytics dashboard, real-time data is no longer optional—it's essential.