RPC and indexing services
RPC and indexing services give outside systems access to a running NEAR node and its chain data. JSON-RPC provides direct node views and transaction requests. Rosetta provides a standard ledger view and transaction-building path. Indexing interfaces provide ordered block data for systems that keep their own query store.
For the node services that host these surfaces, see Node client services. For service startup and shutdown, see Node startup and lifecycle. For the chain data path behind these views, see Chain data processing.
External access model
The services read through the node's client, view, and transaction services. They do not keep a second chain state. JSON-RPC and Rosetta are separate request surfaces, while indexer consumers receive assembled chain data for storage in systems they control.
| Surface | System aim | Main result |
|---|---|---|
| JSON-RPC | Provide a direct node interface | Node status, chain views, state views, proofs, and transaction results |
| Rosetta | Provide a standard ledger interface | Network data, balance effects, and transaction construction |
| Indexing interfaces | Provide ordered chain data | Block messages with selected shard, transaction, receipt, outcome, and state-change data |
The request and indexing paths share the node's chain services but produce different kinds of access.
flowchart LR
A[External applications] --> J[JSON-RPC]
A --> R[Rosetta]
D[Indexer consumers] --> I[Indexer data]
J --> N[Node client and view services]
R --> N
I --> N
N --> S[Chain state and storage]
Service boundaries
JSON-RPC and Rosetta are independent HTTP services. Rosetta does not call JSON-RPC first. Both surfaces read the node services directly, so their answers depend on the node's current chain view, retained history, and shard coverage. The indexer is a data interface rather than a second public query database. A consuming system receives ordered messages and owns its final store and query model.
References: chain/…/RPC_ARCHITECTURE.md• L57-65 chain/…/RPC_ARCHITECTURE.md• L282-293 chain/…/indexer.rs• L33-88
JSON-RPC service
The JSON-RPC service is the general-purpose node interface. It accepts JSON-RPC messages, validates their parameters, routes each method to the node service that owns the data, and returns a typed result or a method-specific error.
Request lifecycle
The request path separates wire handling from chain work. The service parses a request, calls a client or view service, serializes the result, and records request and error metrics. User requests can use a sharded RPC pool when a target block or shard is known. Coordinator-forwarded requests use the local handler and preserve the same method contract.
The HTTP boundary also exposes health, status, network, metrics, API description, and optional operator debug routes. Request size and cross-origin rules apply at this boundary.
sequenceDiagram
participant App as Application
participant RPC as JSON-RPC service
participant Pool as Sharded RPC pool
participant View as View service
participant Tx as Transaction service
App->>RPC: JSON-RPC request
RPC->>RPC: Validate method and parameters
alt Shard-aware read
RPC->>Pool: Select a node from block or shard hints
Pool-->>RPC: Local or forwarded result
else Local read
RPC->>View: Typed view request
View-->>RPC: Typed response
end
alt Transaction request
RPC->>Tx: Admit transaction
Tx-->>RPC: Accepted or rejected
end
RPC-->>App: JSON-RPC response
References: chain/…/lib.rs• L332-370 chain/…/lib.rs• L578-670 chain/…/lib.rs• L3286-3299
Node and chain views
Read methods expose blocks, chunks, accounts, contract code and state, access keys, gas prices, validators, receipts, state changes, transaction outcomes, and node status. Callers can identify a block by height or hash or use a finality view. Sharded routing extends reads to nodes that track the requested shard.
Light-client methods add proof-bearing views. They let a remote verifier check chain data against a trusted light-client head. Three additional proof methods are available only when the SPICE protocol feature is enabled, because they read SPICE execution data.
The query surface keeps important data conditions distinct. A caller can distinguish a missing account from an uninitialized universal account. State pagination and proof requests have separate rules. Access-key limits, missing keys, missing global contract code, oversized state, and refused contract calls produce typed conditions rather than one generic failure.
References: chain/…/lib.rs• L636-665 chain/…/lib.rs• L680-909 chain/…/lib.rs• L962-974 chain/…/main.rs• L913-950
Transaction submission
Transaction submission accepts a transaction envelope with one of two forms: a signed transaction or an unsigned external contract call. The service can admit the transaction only or wait until a requested execution level. The older broadcast methods remain available as deprecated compatibility paths.
The Rust client keeps signed-transaction requests as a separate typed request while the wire service uses the common envelope. This preserves the signed-only client shape without changing the JSON form. The request parser accepts the legacy one-value positional form and the object form with wait_until, but it rejects multiple transaction forms or a value encoded as the wrong kind.
When a caller waits for an external call, the service first finds the call's inclusion after the send height. It then follows the included transaction to the requested execution level. A timeout reports whether the transaction was not observed, remained pending, lacked shard coverage, or hit another status error when that cause is available.
References: chain/…/transactions.rs• L14-87 chain/…/transactions.rs• L234-324 chain/…/lib.rs• L985-993 chain/…/lib.rs• L1270-1319 chain/…/lib.rs• L482-489
API contract
The public JSON-RPC contract is described by shared request, response, and error types. OpenAPI describes HTTP paths and schemas. OpenRPC describes method discovery and by-name parameters for clients and code generators. Both descriptions include stable methods, experimental methods, deprecated aliases, result types, and error shapes.
The generators apply compatibility rules so clients can work across node versions and networks. Some fields are optional in the descriptions when nodes may add or omit them. The timeout error's extra cause is one such field. SPICE-only proof methods appear in the generated descriptions only when the matching feature is enabled. The OpenAPI description is versioned as 1.3.41.
The generated OpenRPC document names top-level request fields as method parameters. This keeps discovered methods aligned with the actual by-name JSON-RPC request shape instead of wrapping parameters in an extra object.
References: chain/…/main.rs• L358-455 chain/…/main.rs• L636-719 chain/…/main.rs• L913-950 chain/…/openrpc.rs• L922-1012 chain/…/openrpc.rs• L1033-1142 chain/…/openrpc.rs• L1374-1391
Shared client primitives
The JSON-RPC client gives callers and tests one typed way to use the request service. It separates request construction from transport, so a real HTTP client and an in-process test transport follow the same method contract.
Transport boundary
RpcTransport is the transport boundary. It sends a JSON-RPC body and returns a parsed message. The default transport uses HTTP, streams the response while enforcing a payload limit, and preserves the coordinator header used by sharded RPC forwarding. Callers can replace it without changing typed request methods.
The client also has a small HTTP interface for simple REST-style status calls. The RPC test service uses a real Axum router and a local HTTP listener. This keeps tests close to the production HTTP boundary without requiring a separate external node.
References: chain/…/lib.rs• L36-105 chain/…/lib.rs• L108-188 chain/…/lib.rs• L493-525 chain/…/lib.rs• L44-69 chain/…/lib.rs• L328-342
Typed request surface
JsonRpcClient turns common operations into typed asynchronous results. Its surface covers node status, blocks, chunks, queries, state changes, receipts, validators, proofs, transaction status, transaction submission, and the request-oriented indexer block method. This lets callers handle typed results and RPC errors rather than build JSON for each method.
The client supports both the current structured query request and the older path-and-data form. Its send_tx method accepts either transaction envelope form while preserving the signed-only request type for callers that use it directly.
References: chain/…/lib.rs• L214-231 chain/…/lib.rs• L234-489
Rosetta service
The Rosetta service adapts NEAR chain data and transactions to the Rosetta API. Its aim is to let wallets, exchanges, and shared blockchain tools inspect ledger data and build transactions without using NEAR-specific request types.
Data API
The Data API provides network identity, network status, finalized block history, block transactions, and account balances. Balance reads identify the block used for the result, so a consumer can compare its ledger with a specific chain point.
Rosetta block views focus on balance-changing operations. The adapter represents transaction and receipt effects in Rosetta terms and can include configured NEP-141 token events and gas-key balance effects. Token events are emitted only for committed execution outcomes and only for configured token contracts. Account views separate spendable funds, storage-reserved funds, and locked stake. A finalized block request must name a canonical block.
References: chain/…/RPC_ARCHITECTURE.md• L282-293 chain/…/utils.rs• L252-367 chain/…/utils.rs• L472-531 chain/…/nep141.rs• L10-30 chain/…/transactions.rs• L394-509
Construction API
The Construction API turns intended Rosetta operations into a submitted signed transaction. Offline steps form the transaction and its signing payload. Online steps read current chain data such as a block hash and access-key nonce before the service submits the result through the node transaction service.
The same operation relationships support both construction and block parsing. Block parsing maps account changes to the transaction, receipt, or external call that caused them. Related transaction identifiers connect receipt effects to their source execution, while operation metadata distinguishes deposits, gas prepayment, gas rewards, gas refunds, storage balance, locked stake, and gas-key balance changes. Configured NEP-141 events become token transfer operations with their contract and currency metadata. Validation rejects mismatched accounts, amounts, currencies, signatures, or links instead of changing the caller's intent.
flowchart LR
A[Rosetta operations] --> B[Prepare transaction]
B --> C[Read current node data]
C --> D[Create signing payload]
D --> E[Combine signature]
E --> F[Parse and hash]
F --> G[Submit transaction]
References: chain/…/RPC_ARCHITECTURE.md• L284-293 chain/…/mod.rs• L225-308 chain/…/mod.rs• L604-1029 chain/…/transactions.rs• L17-34 chain/…/transactions.rs• L211-269 chain/…/transactions.rs• L394-509
Network and history scope
Each Rosetta request names the NEAR blockchain and the node's chain ID. The service checks this identity before reading chain data. Historical reads also depend on retained records and shard coverage, so normal garbage collection can limit the history available to Rosetta.
References: chain/…/RPC_ARCHITECTURE.md• L292-293 chain/…/lib.rs• L180-205
Indexing interfaces
The indexing interfaces turn node chain data into block-ordered messages for external systems. They support a stream-oriented consumer and a request-oriented JSON-RPC fetch. The consuming system owns the final database and query model.
Streamed block data
The stream interface delivers a block message with shard entries. An entry can include a new chunk, signed or external-call transactions, execution outcomes, receipt outcomes, instant receipts, and state changes available to the node. The assembler joins the related block, chunk, transaction, receipt, outcome, and state-change records before delivery.
External-call entries use a distinct transaction variant. They carry the contract, payload, optional state initialization, and the inclusion identifier that links the call to its outcome. Consumers must handle this variant separately from signed transactions.
References: chain/…/indexer.rs• L70-77 chain/…/indexer.rs• L92-183 chain/…/openapi.json• L23559-23600 chain/…/openrpc.json• L13650-13690
Request-oriented indexing
The EXPERIMENTAL_indexer_block method assembles one historical block through JSON-RPC. It is useful when a consumer needs a point lookup instead of a long-lived stream. The response reports the shard coverage used during assembly and preserves the indexer's distinction between unavailable and incomplete data.
Assembly is bounded by a concurrency limit and a 32 MiB serialized response limit. The node must retain the execution outcomes, receipts, state changes, and indexes needed to build the requested block. Archive mode alone does not guarantee that all required records remain available.
References: chain/…/indexer.rs• L25-88 chain/…/indexer.rs• L177-182 chain/…/lib.rs• L559-575 chain/…/lib.rs• L870-875 chain/…/main.rs• L946-950
Data coverage
Indexer data reflects what the node tracks and retains. A tracked shard can have no new chunk in a block. Missing outcomes, receipts, state changes, or applied chunks prevent the service from claiming a complete block message. Consumers must use the reported coverage and treat unavailable or incomplete results as data-service conditions.
References: chain/…/indexer.rs• L56-74 chain/…/indexer.rs• L100-176 chain/…/openrpc.rs• L1135-1142
Change checklist
When these files or sections are changed, remember to consider these:
- When a transaction request type changes, keep the signed-only Rust request, common envelope, parser, client method, runtime handler, and generated OpenAPI and OpenRPC schemas aligned.
- When positional or object parameters change, preserve the supported wire forms and keep
wait_untilbehavior consistent across current and deprecated submission methods. - When transaction kinds change, check submission, status lookup, inclusion waiting, indexer messages, and consumers that assume every transaction is signed.
- When a JSON-RPC method or result changes, update the handler, typed client surface, OpenAPI entry, OpenRPC entry, and checked-in descriptions together.
- When a proof method depends on SPICE data, keep the runtime handler and both generated descriptions on the same feature boundary.
- When request routing changes, keep local handling, coordinator forwarding, shard coverage, response limits, and the coordinator header aligned.
- When the RPC test harness changes, keep real client, view, RPC, and optional protocol actors alive for the full HTTP server lifetime.
- When indexer retention or coverage changes, check both streamed messages and
EXPERIMENTAL_indexer_blockresponses. - When Rosetta transaction conversion changes, keep execution causes, related receipts, external calls, balance sub-accounts, gas-key effects, and configured NEP-141 events aligned with their operation metadata.
- When NEP-141 event handling changes, preserve the committed-outcome filter and the contract-to-currency configuration boundary.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A request uses both transaction fields or encodes one field as the wrong transaction kind | Parameter parsing rejects the request | Send exactly one correctly encoded transaction form |
A caller uses positional parameters for wait_until | The request is rejected because the wait field is supported in object form | Use an object request when setting wait_until |
| An external call is sent through an API that expects an inclusion hash immediately | The asynchronous result can be null because the inclusion identifier does not exist yet | Use send_tx when the caller needs a waitable result |
| A waiting request targets a shard the node cannot track | The request times out without the requested execution result | Use a node or RPC pool with coverage for the target shard |
| A non-SPICE build advertises a SPICE-only proof method | The method is absent or cannot read the required data | Gate runtime handlers and generated descriptions together |
| A generated schema requires a field that an older node omits | A generated client rejects a valid rolling-upgrade response | Preserve compatibility transforms and optional fields in both schema formats |
| A test setup stops the server or actor system before the request ends | Tests fail during teardown or no longer exercise the production path | Keep the server task and real actors alive until TestSetup is dropped |
| The indexer lacks retained outcomes, receipts, state changes, or applied chunks | A block request is unavailable or incomplete | Retain the records needed for the requested history and use reported coverage |
| An assembled indexer response exceeds 32 MiB | The request is rejected rather than truncated | Reduce the request scope or use a suitable indexing path |
| A Rosetta request names the wrong blockchain or chain ID | The service rejects it before reading chain data | Use the identity returned by Rosetta network discovery |
| A NEP-141 event is logged by a failed or unknown execution outcome | Rosetta omits the token event because the outcome did not commit | Treat only successful receipt outcomes as token balance changes |
Key files
| File | Why to read it |
|---|---|
| chain/…/lib.rs | Defines JSON-RPC method routing, shard-aware handling, transaction submission and waiting, HTTP routes, and RPC configuration. |
| chain/…/transactions.rs | Defines transaction parameter forms, envelope decoding, and compatibility checks for submission and status requests. |
| chain/…/indexer.rs | Defines block assembly, coverage reporting, validation, concurrency, and response limits for indexer data. |
| chain/…/lib.rs | Defines the transport boundary and typed client calls used by callers and tests. |
| chain/…/lib.rs | Shows how real node actors run behind an HTTP-served RPC router for request tests. |
| chain/…/main.rs | Generates the OpenAPI contract and gates feature-specific methods. |
| chain/…/openrpc.rs | Generates OpenRPC discovery, by-name parameters, schemas, tags, and deprecated method entries. |
| chain/…/mod.rs | Shows the two-way conversion between NEAR actions and Rosetta operations. |
| chain/…/transactions.rs | Maps state changes, execution causes, external calls, gas keys, and configured token events into Rosetta transactions and operations. |
| chain/…/nep141.rs | Defines how committed NEP-141 logs become configured fungible-token events and how token balances are read. |
| chain/…/utils.rs | Shows shared Rosetta account, network, access-key, and finalized-block queries. |
| chain/…/RPC_ARCHITECTURE.md | Gives the service-level map of JSON-RPC, Rosetta, and shared node data paths. |