Optimism
هل أنت مستعد لاستدعاء هذا في الإنتاج؟
الخطة المجانية تغطي المشاريع الشخصية. الدفع حسب الاستخدام يتوسع دون بطاقة.
Optimism
الخطة المجانية تغطي المشاريع الشخصية. الدفع حسب الاستخدام يتوسع دون بطاقة.
TheRPC exposes OP Mainnet through the standard JSON-RPC 2.0 specification, so the API behaves exactly as it would against any Ethereum-equivalent execution client — a natural fit for an OP Stack rollup that settles to Ethereum L1. Four traits define the architecture: standard HTTP and WebSocket endpoints under optimism.therpc.io, API-key authentication on every request, a unified response envelope that always returns either a result or an error, and cross-network compatibility — the same request shapes you use on OP Mainnet (chain ID 10) work across every other chain TheRPC serves by swapping only the endpoint host.
The HTTP endpoint is the right choice for single, stateless requests and straightforward integrations against OP Mainnet — reading a balance, fetching a Bedrock block, submitting a transaction, or running batch calls. Each request opens a connection, returns one response, and closes, which keeps backend services and scripts simple. See the HTTP/Curl guide for ready-to-run request examples.
The WebSocket endpoint is ideal for subscriptions and real-time data on OP Mainnet, where a persistent connection lets you stream new blocks as they land roughly every 2 seconds and watch logs as they appear — far more efficient than polling for a fast L2. Use eth_subscribe to open subscriptions for newHeads, logs, and pending transactions; see its reference for full subscription examples.
Every call to OP Mainnet uses the JSON-RPC 2.0 request format, a small JSON object with four fields. jsonrpc is always the string "2.0"; method names the procedure to invoke, such as eth_blockNumber; params is an array of arguments (empty when the method takes none); and id is a client-chosen value echoed back in the response so you can match replies to requests when several are in flight.
Every OP Mainnet response shares the same consistent structure: a jsonrpc field set to "2.0", the id echoed back from your request, and exactly one of result (on success) or error (on failure). This predictable envelope means your client can branch on the presence of error once and reuse that logic across every method and every chain TheRPC serves.
Every request to OP Mainnet must carry your TheRPC API key in the Authorization header using the Bearer scheme. The key both authenticates the request and ties usage to your plan's quota. See the full Authentication guide for how to generate, store, and rotate keys safely.
OP Mainnet methods split into standard and advanced groups. The standard set covers eth_ for core protocol operations (balances, blocks, transactions, contract calls), net_ for network status, and web3_ for utility helpers. The advanced set covers debug_ for step-by-step debugging, trace_ for full transaction tracing, and txpool_ for inspecting the pending transaction pool. Each prefix links to its own method docs, where you'll find parameters, return shapes, error codes, and examples specific to OP Mainnet.
When a call to OP Mainnet fails, the error object carries one of the five standard JSON-RPC codes: -32700 for a parse error (malformed JSON), -32600 for an invalid request, -32601 when the method is not found, -32602 for invalid params, and -32603 for an internal error. See the FAQ for detailed error-handling strategies, including retries and backoff.
requests; see the Python guide.