JSON-RPC API Reference

Overview

OPN Chain provides a complete Ethereum-compatible JSON-RPC API, allowing seamless integration with existing Ethereum tools and libraries. This API follows the Ethereum JSON-RPC specification exactly, ensuring maximum compatibility.

Quick Reference

Endpoint URLs

Network
HTTP Endpoint
WebSocket Endpoint

Testnet

https://testnet-rpc.iopn.tech

wss://testnet-ws.iopn.tech

Mainnet

https://rpc.iopn.tech

wss://ws.iopn.tech

Supported Namespaces

  • web3_* - Web3 specific methods

  • net_* - Network information

  • eth_* - Ethereum compatible methods

  • debug_* - Debug and trace methods

  • txpool_* - Transaction pool information

Making Requests

HTTP Requests

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

WebSocket Connections

Method Categories

1. Web3 Methods

Basic client and utility methods:

  • web3_clientVersion - Get client version

  • web3_sha3 - Keccak-256 hash function

2. Network Methods

Network status and information:

  • net_version - Network ID

  • net_listening - Listening status

  • net_peerCount - Connected peer count

3. Ethereum Methods

Core blockchain functionality:

  • Reading: eth_getBalance, eth_getCode, eth_getStorageAt

  • Transactions: eth_sendRawTransaction, eth_getTransactionReceipt

  • Blocks: eth_getBlockByNumber, eth_getBlockByHash

  • Filters: eth_newFilter, eth_getFilterChanges

  • Gas: eth_gasPrice, eth_estimateGas

4. Debug Methods

Advanced debugging capabilities:

  • debug_traceTransaction - Detailed transaction traces

  • debug_traceBlockByNumber - Block execution traces

Request Format

All requests must follow the JSON-RPC 2.0 specification:

Request Fields

Field
Type
Description

jsonrpc

string

Always "2.0"

method

string

The method name

params

array

Method parameters

id

number/string

Request identifier

Response Format

Success Response

Error Response

Error Codes

Code
Message
Description

-32700

Parse error

Invalid JSON

-32600

Invalid request

Invalid request format

-32601

Method not found

Method does not exist

-32602

Invalid params

Invalid method parameters

-32603

Internal error

Internal JSON-RPC error

-32000

Server error

Generic server error

Rate Limits

Default Limits

Endpoint Type
Rate Limit
Window

Public HTTP

100 req/sec

Per IP

Public WebSocket

100 msg/sec

Per connection

Authenticated

1000 req/sec

Per API key

Rate Limit Headers

Best Practices

1. Connection Management

2. Error Handling

3. Batch Requests

Common Use Cases

Get Current Block Number

Check Account Balance

Send Transaction

Subscribe to New Blocks

Testing Your Integration

Health Check Script

Migration from Ethereum

Migrating from Ethereum RPC requires minimal changes:

Troubleshooting

Connection Refused

  • Check if you're using the correct endpoint URL

  • Verify your firewall settings

  • Try using a different network

Invalid Response

  • Ensure you're sending valid JSON

  • Check method names are correct

  • Verify parameters match expected types

Rate Limiting

  • Implement exponential backoff

  • Use batch requests when possible

  • Consider upgrading to authenticated access


Last updated