RPC API contracts and clients
Celestia Node exposes typed service contracts over JSON-RPC for applications and operators. The contracts cover chain data, shares, blobs, state, data availability, Fibre data transfer, peer operations, node administration, and blobstream proofs. The same contracts also guide client libraries and the OpenRPC description. See Public APIs and node operations, Node RPC service wiring, Command-line node operations, and Blob lifecycle services.
Contract model
The RPC contract separates a service's behavior from the transport that exposes it. Each service defines a Module interface for its behavior and an API wrapper for RPC calls. The wrapper carries method names and permission marks that the server and client use as one public contract.
Service interfaces
The service interface is the main agreement between node assembly and callers. A node can provide a different service implementation while keeping the method shape stable for clients. The RPC wrapper forwards calls to that service and does not make the client depend on the node's internal wiring.
The public contract uses these service groups:
| Namespace | Main purpose |
|---|---|
header | Read local and network headers, sync state, and header updates |
share | Read shares, rows, samples, data squares, namespace data, and proofs |
blob | Submit, read, verify, and watch application blobs |
blobstream | Build data-root tuple roots and inclusion proofs over block ranges |
das | Read sampling statistics and wait for data-availability catch-up |
state | Read account state and submit transfers, blob-payment, and delegation actions |
fibre | Transfer blobs and manage Fibre payment and escrow operations |
p2p | Inspect and control peers, connections, bandwidth, and resource state |
node | Read node status and control logs and authentication tokens |
References: nodebuilder/…/header.go• L12-18 nodebuilder/…/share.go• L17-33 nodebuilder/…/blob.go• L13-20 nodebuilder/…/blobstream.go• L9-25 nodebuilder/…/das.go• L11-17 nodebuilder/…/state.go• L16-22 nodebuilder/…/p2p.go• L38-42 nodebuilder/…/node.go• L10-14 api/…/read_client.go• L30-35 api/…/examples.go• L189-238
Namespace contract
The namespace is part of the wire name of a method. For example, the header service is reached through the header namespace and the blob service through blob. The server registration map and the client map must use the same names, so a namespace change is an API change even when method signatures stay the same.
The public RPC client groups each namespace under a typed field such as Header, Blob, or Fibre. It opens one JSON-RPC connection for each registered namespace and closes all of them through the client's Close method.
References: api/…/client.go• L28-40 api/…/client.go• L59-100 nodebuilder/…/constructors.go• L18-39
Client interfaces
The repository offers two client levels for different callers. The namespace client maps directly to the node's RPC surface. The application client combines read access with optional transaction, blob submission, and Fibre operations.
Namespace client
api/rpc/client is the direct JSON-RPC client. NewClient accepts an endpoint and an optional token, then returns typed service groups for all public namespaces. It is suited to applications that need the node API as exposed and does not manage keys or build chain transactions.
The client sends a supplied token as Authorization: Bearer <token> to each namespace. A caller should close the client when it no longer needs the connections.
References: api/…/client.go• L28-40 api/…/client.go• L59-85
Application client
api/client is a higher-level client for applications that need both data access and submission. Its read side connects to the Bridge node's share, blobstream, header, blob, and fibre namespaces. Its submit side uses a keyring and a Core gRPC connection for chain transactions and local Fibre operations rather than routing Fibre writes through a Bridge node.
This split lets an application use NewReadClient without a signing key. A full client adds state, blob submission, and local Fibre actions only when it has a valid keyring and submission configuration. The client captures the keyring at construction time, so later keyring changes require client reinitialization. The test keyring backend stores keys in plain text and is intended for test use. The helper that creates a missing key prints its mnemonic, so production callers must protect the key store and recovery data.
References: api/…/read_client.go• L18-35 api/…/read_client.go• L48-128 api/…/client.go• L25-40 api/…/client.go• L81-112 api/…/client.go• L114-199 api/…/keyring.go• L17-64 api/…/client_test.go• L53-110 api/…/client_test.go• L281-356
Read and submit paths
The read-only and full clients have different safety boundaries. A read-only blob client rejects Submit instead of silently trying to submit without a signer. A full client uses its configured default key for chain and Fibre submission. Submission can be immediate, queued with one signer, or parallel with worker accounts. Parallel submission does not guarantee the order of the input blobs.
The main application flow is:
flowchart LR
A[Application] --> B{Client choice}
B --> C[Read client]
B --> D[Full client]
C --> E[Bridge JSON-RPC]
D --> E
D --> F[Keyring signer]
D --> G[Core gRPC]
F --> G
G --> H[Chain transaction]
G --> I[Local Fibre operations]
E --> J[Headers shares blobs proofs]
H --> K[Submitted blob or state action]
I --> L[Fibre result]
References: api/…/client.go• L114-199 api/…/read_client.go• L66-128 api/…/client_test.go• L112-279 api/…/client_test.go• L281-356
API description
The repository generates an API description from the same service contracts that serve requests. This keeps method names, summaries, permissions, schemas, examples, deprecation markers, and source links close to the types that define the public behavior. The generated method descriptions also include the required bearer-auth setup and a request example for HTTP or WebSocket use.
OpenRPC generation
OpenRPC is a machine-readable description format for JSON-RPC APIs. The api/…/openrpc.go flow reads Module interfaces and their comments, reads permission marks from the client API wrappers, reflects the registered client modules, and emits method names in the form <namespace>.<method>.
The generator also describes the bearer authorization header, maps public values to JSON schemas, adds representative schema examples, marks methods whose comments start with Deprecated:, and links each method to the default service implementation. Each method description includes the permission level and the command used to create a node token. Regular methods include an HTTP curl example. Subscription methods that return a channel instead describe a WebSocket upgrade and JSON-RPC request because HTTP POST does not support them. The celestia docgen command discovers the registered modules and writes the resulting OpenRPC document to standard output.
References: api/…/openrpc.go• L1-7 api/…/openrpc.go• L57-90 api/…/openrpc.go• L93-219 cmd/…/docgen.go• L14-48
Schema examples
The schema example support gives the API description representative values for public request and result types. It combines generic values with embedded examples for extended headers, sampling statistics, transaction responses, resource-manager statistics, blobs, blob proofs, Fibre transfer results, payment promises, escrow accounts, and pending withdrawals. These values help API consumers understand the JSON shape without making live RPC calls.
The example builder also accounts for values whose JSON form differs from their basic Go kind. The OpenRPC schema mapper represents node types and integer values in the forms used by the public API.
References: api/…/examples.go• L41-59 api/…/examples.go• L68-238 api/…/examples.go• L241-307 api/…/openrpc.go• L187-199 api/…/openrpc.go• L222-271 api/…/extendedHeader.json• L1-77 api/…/resourceManagerStats.json• L1-88
Contract checks
The RPC tests check that the client API and the service interfaces have matching method types across the public modules, including Fibre. They also check that return values can be encoded for JSON-RPC, that permission levels allow only the intended calls, and that calls reach the underlying service. Application client tests also cover the read-only submission boundary, signed submission with default and alternate keys, queued submission, and local Fibre escrow actions. OpenRPC generation checks that every discovered method documents its permission, token command, bearer header, and the correct HTTP or WebSocket request pattern. Server tests also guard the authentication and CORS mode selected for each endpoint, TLS startup and transport, server lifecycle, and WebSocket subscriptions when metrics are enabled. These checks protect the boundary where a Go type change can otherwise become a wire-format, authorization, documentation, transport, or client compatibility break.
References: api/rpc_test.go• L125-159 api/rpc_test.go• L161-266 api/rpc_test.go• L268-327 api/…/client_test.go• L112-356 api/…/client_test.go• L367-406 api/…/openrpc_test.go• L15-60 api/…/server_test.go• L34-138 api/…/server_test.go• L210-490
Authentication boundary
Authentication controls access at the RPC server rather than inside each service. The server presents a protected view of each API and compares the permissions in a signed token with the permission required by the requested method.
Permission tiers
Permissions form an ordered access model. A token with a stronger level includes the lower levels that it needs for normal use.
| Level | Access purpose |
|---|---|
public | Methods that need no stronger access level |
read | Node, chain, network, and data queries |
write | Transactions and blob submission |
admin | Node control, peer control, and token administration |
The method mark is the source of the required level. For example, blob submission, state-changing actions, and Fibre actions use write, while peer control and node token operations use admin. Read methods use read.
References: api/…/permissions.go• L12-19 nodebuilder/…/blob.go• L49-90 nodebuilder/…/state.go• L116-190 nodebuilder/…/p2p.go• L265-290 nodebuilder/…/node.go• L34-42 nodebuilder/…/constructors.go• L31-39
Token boundary
Tokens are signed JWT values. Their payload carries the allowed permission set and can carry an expiry time. Clients send the token in the HTTP Authorization header. The server verifies it before the request reaches the service wrapper. Without a token, an authenticated server permits only methods with the default read access.
The node service can create or verify tokens through its administrative API. The command-line client can also load the node's signing secret from the node store and build a token for RPC use. This makes the signing secret a node boundary: a caller needs access to the node's protected key material to create equivalent tokens.
References: api/…/permissions.go• L21-61 api/…/server.go• L184-205 nodebuilder/…/node.go• L24-29 cmd/auth.go• L25-70 cmd/rpc.go• L55-99 api/…/server_test.go• L272-342
Service registration boundary
The server applies permission checks when it registers a service. With authentication enabled, it exposes a permission-aware view of the service and keeps the internal implementation behind that view. When authentication is disabled, it registers the service directly and uses permissive CORS so that the endpoint has no browser-origin restriction.
This is a deployment boundary rather than a service-level choice. A service method must keep its permission mark aligned with the action it performs because the server uses that mark before the method runs.
References: api/…/server.go• L224-238 api/…/server_test.go• L109-138 api/…/server_test.go• L272-342
Transport credentials
The JSON-RPC and Core gRPC paths use separate transport contracts. The JSON-RPC client uses an HTTP bearer token. The Core gRPC client can use TLS and sends its configured token as x-token; without TLS, a configured token is exposed on the network.
The read client can add a bearer token or custom HTTP headers for Bridge access. It warns when a token is used without TLS. Applications should keep the token and its transport aligned with the endpoint that verifies it.
References: api/…/client.go• L64-71 api/…/read_client.go• L18-64 api/…/grpc.go• L19-29 api/…/grpc.go• L37-81
Endpoint controls
The RPC endpoint can require TLS and can restrict browser access through configured CORS rules. The server also bounds request size, request time, header size, idle time, and concurrent connections. Optional per-IP rate limiting is disabled by default; when a reverse proxy handles the endpoint, rate limiting belongs at that proxy because the server sees the proxy address rather than each client address.
The endpoint can enable OTel metrics for request, connection, and RPC method activity. The metrics wrapper preserves WebSocket upgrades, so subscription methods continue to work when metrics are enabled. Middleware order places rate limiting outside the connection limit, authentication and CORS around the RPC handler, and metrics close to the RPC handler.
The node RPC configuration validates the bind address, port, and TLS files before the server starts. Authentication is enabled by default. Skipping authentication is an explicit deployment choice that also allows permissive CORS behavior. TLS startup still checks that the configured certificate and key can load before serving requests.
References: nodebuilder/…/config.go• L12-46 nodebuilder/…/config.go• L48-125 nodebuilder/…/constructors.go• L42-57 api/…/server.go• L28-35 api/…/server.go• L109-181 api/…/server.go• L240-292 api/…/server_test.go• L34-208 api/…/server_test.go• L344-490
Service contract groups
The service groups give callers a path from chain data to application data and node operations. The groups are separate at the RPC boundary, but applications often combine them: headers identify a block, share and blob calls read its data, and state or Fibre calls submit the transaction that carries or supports application data.
Data and proof services
The header service exposes local and network head views, height and hash lookup, sync state, wait operations, and header subscriptions. The share service uses a height and coordinates or namespace to return data from the extended data square. The blobstream service works across ordered block ranges to return data-root tuple roots and inclusion proofs.
These services support both direct reads and proof-backed application flows. A caller can first identify a block through headers, locate data through shares or blobs, and then ask for the proof form needed by its consumer.
References: nodebuilder/…/header.go• L16-54 nodebuilder/…/share.go• L33-75 nodebuilder/…/blobstream.go• L12-25
Blob and state services
The blob service is the application data contract. It accepts blob submission and provides lookup, batch retrieval, inclusion checks, commitment proofs, and namespace subscriptions. The state service covers account and balance queries plus chain actions such as transfers, pay-for-blob submission, and delegation changes.
Blob submission is a write operation because it can create a chain transaction. Blob retrieval and proof calls are read operations. State queries and state-changing actions follow the same separation, which lets an application use a limited read token for inspection without granting transaction authority.
References: nodebuilder/…/blob.go• L16-46 nodebuilder/…/blob.go• L49-90 nodebuilder/…/state.go• L22-110 nodebuilder/…/state.go• L117-190
Fibre services
The fibre service supports application data transfer together with the payment state needed for that transfer. Its public results describe uploaded or submitted blobs, payment promises, escrow accounts, and pending withdrawals. The full application client routes these operations through its local consensus connection, while a read client can consume the Bridge RPC contract.
This service extends the normal read and submit boundary rather than replacing it. Public Fibre queries can support inspection, while operations that move data or funds require the appropriate write access and client signing setup. The application client tests verify that escrow deposits, withdrawals, and related queries use the local consensus path; upload and transfer flows require a Fibre-enabled network.
References: api/…/read_client.go• L30-35 api/…/client.go• L154-199 api/…/client_test.go• L281-356 api/…/examples.go• L184-238
Node and network services
The node service supports operational inspection and control. It reports node information and readiness, changes log levels, and manages authentication tokens. The p2p service exposes peer and connection views plus actions such as connect, close, block, unblock, protect, and unprotect.
These methods are for operators rather than ordinary data users. Their admin boundary prevents a read-only application credential from changing node behavior or network relationships.
References: nodebuilder/…/node.go• L14-29 nodebuilder/…/node.go• L34-42 nodebuilder/…/p2p.go• L42-107 nodebuilder/…/p2p.go• L265-290
Availability service
The das service reports the node's data-availability sampling state. Applications and operators can read sampling statistics or wait until the sampler catches up to the network head. This gives callers a node-level availability signal without exposing the sampler's internal workers.
References: nodebuilder/…/das.go• L12-24
Change checklist
When these files or sections are changed, remember to consider these:
- Keep every namespace name aligned across nodebuilder/…/constructors.go, api/…/client.go, server registration, and OpenRPC receiver registration.
- Treat a change to a
Modulemethod as a wire-contract change. Update itsAPIwrapper, client field, generated mocks, and method documentation together. - Keep
permmarks aligned with the intended access boundary. A missing or stronger mark can silently change which tokens can call a method. - Check JSON encoding and OpenRPC schema output when changing a public argument or return type.
- Keep the OpenRPC method comments, permission marks, deprecation markers, and receiver registration aligned with the public method set.
- Keep generated authentication guidance aligned with permission marks and transport type. HTTP methods need a curl request example, while subscription methods need WebSocket upgrade guidance.
- When changing a public type, update its schema example or confirm that the generic example builder can construct and encode it.
- Keep JSON-RPC bearer authentication separate from Core gRPC
x-tokenauthentication. They may use different endpoints and trust settings. - Preserve the read-only behavior when changing blob or Fibre client composition. Read clients must not gain an implicit signer or submission path.
- Keep TLS, CORS, request limits, metrics middleware, and rate-limit settings aligned with the address and reverse-proxy boundary that exposes the RPC endpoint.
- Preserve WebSocket upgrade support when changing HTTP middleware around RPC subscriptions.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A namespace differs between server registration and client construction | The typed client cannot call that service | Change the namespace maps, constructors, and OpenRPC registration as one contract |
| A service method and its API wrapper have different types | Calls fail at the RPC boundary or the client no longer matches the service | Keep the interface and wrapper signatures identical; contract tests check this |
A protected method has an incorrect perm mark | A caller gets too much access or a valid token is rejected | Review permission marks with the service's business action |
| An embedded schema example is invalid or a public type has no usable example | The docgen package can fail during setup or discovery cannot produce the API document | Keep example fixtures valid and ensure new public types have a supported example path |
| OpenRPC authentication guidance omits the method permission or uses the wrong transport example | Operators may send an invalid request or expose a subscription method through the wrong transport | Keep permission data and method descriptions aligned; the OpenRPC authentication checks cover HTTP and WebSocket methods |
| An expired or incorrectly signed JWT reaches the server | The request is rejected before the service runs | Create tokens with the node secret and set the correct bearer header |
| Authentication is disabled on an exposed endpoint | All registered methods are reachable and CORS allows all origins, methods, and headers | Treat authDisabled as an explicit trusted-network deployment choice |
| A token is sent without TLS | The token can be exposed in transit | Enable TLS for token-bearing HTTP and gRPC connections |
| Rate limiting is enabled behind a reverse proxy | Different clients consume one shared bucket and valid calls can receive 429 responses | Apply client-IP rate limiting at the proxy or preserve the real client address |
| TLS is enabled without valid certificate and key files | The RPC server fails validation or cannot start | Set both paths and verify the files before startup |
| Metrics middleware does not preserve WebSocket hijacking | Subscription calls fail even though unary RPC calls still work | Keep the WebSocket subscription test enabled when changing the handler stack |
A read-only client calls Blob.Submit or a Fibre write operation | Submission fails because no signer-backed path exists | Use the full client with a keyring and Core submission settings |
| A public return type cannot be JSON encoded | RPC calls or OpenRPC discovery fail for that contract | Preserve JSON-marshaling support for all public return values |
Key files
| File | Why to read it |
|---|---|
| api/…/client.go | Defines the direct JSON-RPC client and namespace map |
| api/…/client.go | Defines the full application client and chain and local Fibre submission boundary |
| api/…/read_client.go | Defines Bridge read access, Fibre read access, and HTTP authentication inputs |
| api/…/keyring.go | Defines application keyring setup and missing-key behavior |
| api/…/grpc.go | Defines the Core gRPC transport and token boundary |
| api/…/wrappers.go | Shows how read-only and submitting blob clients differ |
| api/…/readme.md | Gives the supported client modes and their submission and keyring expectations |
| api/…/example.go | Shows the application path from client setup to blob submission and retrieval |
| api/…/server.go | Defines RPC registration, authentication, transport protection, limits, and lifecycle |
| api/…/server_test.go | Guards authentication, CORS, TLS, lifecycle, and WebSocket behavior in the server boundary |
| api/…/permissions.go | Defines token permissions and JWT payloads |
| api/…/openrpc.go | Defines the conversion from service contracts to an OpenRPC document and its transport-specific authentication guidance |
| api/…/openrpc_test.go | Verifies generated authentication guidance for HTTP and WebSocket methods |
| api/…/examples.go | Defines representative values for generated public schemas |
| api/…/extendedHeader.json | Shows the public JSON shape used for an extended header example |
| api/…/resourceManagerStats.json | Shows the public JSON shape used for node resource statistics |
| cmd/…/docgen.go | Shows the operator-facing API documentation command |
| nodebuilder/…/config.go | Defines RPC endpoint, TLS, CORS, and rate-limit settings |
| nodebuilder/…/constructors.go | Shows how node service modules become registered RPC endpoints |
| nodebuilder/default_services.go | Lists the service APIs used for discovery |
| nodebuilder/…/blob.go | Illustrates blob read, proof, subscription, and submission contracts |
| nodebuilder/…/state.go | Illustrates query and transaction contract boundaries |
| api/rpc_test.go | Shows the compatibility and authorization checks for the public RPC surface |