JSON-RPC API for OKTC: Complete Guide to Supported Methods and Usage

ยท

The OKT Chain (OKTC) offers a robust and Ethereum-compatible JSON-RPC interface, enabling developers to interact with the blockchain using familiar tools and protocols. This guide provides a comprehensive overview of all supported JSON-RPC methods across various namespaces, including Web3, Eth, Personal, WebSocket, and TXPool. Whether you're building decentralized applications (dApps), querying blockchain data, or managing transactions, this resource will help you leverage the full power of OKTCโ€™s API.


Mainnet Configuration

OKTC Mainnet operates with the following chain identifiers:

To connect to the network, use the official public RPC endpoint:

๐Ÿ‘‰ Discover how to securely connect your dApp to OKTC Mainnet


Prerequisites for Using JSON-RPC

Before diving into method usage, ensure you're familiar with:

OKTC is designed to be compatible with Ethereum tooling, so most Web3 libraries (like Web3.js or Ethers.js) work seamlessly.


How to Start HTTP JSON-RPC Calls

You can initiate JSON-RPC requests using tools like curl or by running a local node via Geth-like clients.

Using curl (Recommended for Quick Testing)

curl -X POST https://exchainrpc.okex.org \
  -H "Content-Type: application/json" \
  --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'

Using Geth or Compatible Client

While OKTC does not support direct Geth execution, you can use compatible EVM clients. For development purposes, consider using frameworks like Hardhat or Foundry that support custom chain configurations.

๐Ÿ‘‰ Learn how to set up your development environment for OKTC integration


Supported JSON-RPC Methods Overview

Below is a categorized breakdown of all supported JSON-RPC methods on OKTC. Unsupported methods have been omitted for clarity and relevance.

Core Keywords


Web3 Namespace Methods

These methods provide client-level information.

web3_clientVersion

Returns the current client version.

Example Response

{ "jsonrpc": "2.0", "id": 1, "result": "oktc/v1.0.0" }

web3_sha3

Computes Keccak-256 hash (not SHA3-256) of the input data.

Parameters

Example

{ "jsonrpc": "2.0", "method": "web3_sha3", "params": ["0x68656c6c6f"] }

Net Namespace Methods

Provides network-level details.

net_version

Returns the current network ID (66 for OKTC Mainnet).

Example Response

{ "result": "66" }
Note: net_peerCount and net_listening are not supported on OKTC.

Eth Namespace Methods

The most widely used namespace for blockchain interaction.

eth_protocolVersion

Returns the Ethereum protocol version in use.

eth_syncing

Indicates whether the node is syncing. Returns false when fully synced.

eth_gasPrice

Returns the current gas price in OKT.

Example Response

{ "result": "0x3B9ACA00" } // e.g., 1 gwei

eth_accounts

Lists all available account addresses managed by the node.

eth_blockNumber

Returns the latest block height.

eth_chainId

Returns chain identifier in hex: 0x42.

Account & Balance Queries

eth_getBalance(address, blockNumber)

Fetches account balance in wei (convertible to OKT).

eth_getTransactionCount(address, blockNumber)

Gets the number of transactions sent from an address (nonce).

Smart Contract Interactions

eth_getCode(address, blockNumber)

Retrieves deployed bytecode at a contract address.

eth_call(transactionObject, blockNumber)

Executes a read-only call to a contract function without broadcasting a transaction.

Use Cases:

eth_estimateGas(transactionObject)

Estimates gas required for a transaction.

๐Ÿ‘‰ Optimize gas usage in your dApp with real-time estimation tools


Transaction Lifecycle Management

Sending Transactions

eth_sendTransaction(object)

Sends a signed transaction from a local account.

Requires unlocked account via personal_unlockAccount.

eth_sendRawTransaction(data)

Broadcasts a pre-signed transaction.

Useful for wallets that sign offline.


Block and Transaction Data Retrieval

eth_getBlockByNumber(number, includeFullTx)

Returns block details. Set second parameter to true for full transaction objects.

eth_getBlockByHash(hash, includeFullTx)

Same as above but uses block hash.

eth_getTransactionByHash(txHash)

Gets detailed transaction info.

eth_getTransactionReceipt(txHash)

Returns receipt after confirmation โ€“ essential for checking success and logs.


Event Filtering and Logs

OKTC supports log filtering for event tracking.

eth_newFilter(filterObject)

Creates a filter to monitor logs matching criteria (e.g., contract events).

eth_newBlockFilter()

Triggers notifications on new blocks.

eth_newPendingTransactionFilter()

Notifies when new pending transactions appear.

Polling Filters


WebSocket Subscription Methods

For real-time updates without polling.

eth_subscribe(subscriptionType, options)

Subscribe to events like:

Returns a subscription ID.

eth_unsubscribe(subscriptionId)

Stops receiving updates for a subscription.


Personal Namespace Methods

Manage accounts directly on the node (use with caution in production).

Account Management

Signing & Recovery

โš ๏ธ Never expose private keys or passphrases in client-side code.

TXPool Methods

Inspect pending transactions in the mempool.

txpool_content

Full details of all pending and queued transactions.

txpool_inspect

Formatted summary for debugging (e.g., top senders/receivers).

txpool_status

Counts of pending and queued transactions.

Useful for monitoring network congestion.


Frequently Asked Questions (FAQ)

Q: Which Ethereum RPC methods are fully supported on OKTC?
A: OKTC supports most standard Eth, Web3, and Personal methods used for dApp development, including transaction submission, balance checks, contract calls, and event filtering. Unsupported methods are typically mining or legacy DB-related functions.

Q: Can I use MetaMask with OKTC?
A: Yes. Add a custom RPC network in MetaMask with Chain ID 66 and connect to https://exchainrpc.okex.org.

Q: How do I handle gas pricing on OKTC?
A: Use eth_gasPrice to fetch current rates. Transactions require gas priced in OKT. Fees vary based on network load.

Q: Is WebSocket supported for live updates?
A: Yes. Use eth_subscribe over WebSocket for real-time block, log, and transaction events.

Q: Are there rate limits on the public RPC endpoint?
A: The public node may apply throttling under heavy load. For high-frequency applications, consider running your own node or using dedicated infrastructure providers.

Q: How can I debug failed transactions?
A: Use eth_getTransactionReceipt to check status. If status is 0, the transaction failed. Combine with simulation tools or local forks for deeper analysis.


Start building powerful, scalable dApps on OKTC today using its full-featured JSON-RPC interface designed for seamless Ethereum compatibility.