Connection and RPC client
The Connection client is the application boundary for Solana node communication. It gives callers one client for HTTP RPC requests and WebSocket event streams while applying shared request policy, converting node data to public client values, and reporting transport or RPC errors. The HTTP RPC operations, WebSocket subscriptions, and Kit adapters pages describe the main paths behind this boundary.
System boundary
The client accepts an HTTP RPC endpoint and creates the related WebSocket endpoint for live events unless the caller supplies one. HTTP work starts through a typed RPC client. Subscription work uses a separate runtime that shares the connection's commitment policy and returns events to application callbacks.
This diagram shows how the client separates request and response work from long-lived event delivery.
flowchart LR
App[Application] --> C[Connection]
C -->|typed RPC request| H[Solana RPC HTTP endpoint]
H --> C
C -->|subscription request| W[Solana RPC WebSocket endpoint]
W -->|notification| C
C --> App
Request configuration
Connection settings define defaults for all requests. A method can add a local configuration or commitment when one operation needs a different view of cluster state.
Endpoint and commitment
The HTTP endpoint must use http: or https:. The client uses an explicit wsEndpoint when present. Otherwise it derives a WebSocket URL from the HTTP endpoint, including the secure WebSocket scheme for HTTPS.
A commitment is the level of cluster agreement requested for a result. The client resolves each request in this order:
- the method's commitment;
- the connection default;
confirmedwhen neither is set.
Methods that only support confirmed or finalized state reject weaker commitment levels. The same resolved value is applied to subscriptions so a read and its related event stream use a consistent view of the cluster.
References: packages/…/connection.ts• L604-627 packages/…/connection.ts• L2682-2704 packages/…/connection.ts• L2755-2829 packages/…/connection.ts• L3652-3684
HTTP transport controls
The connection can change how requests travel without changing the RPC method used by the caller. It adds a client header and JSON request headers, serializes values that include large integers, and passes an abort signal to the fetch layer.
| Setting | Purpose |
|---|---|
httpHeaders | Adds caller headers to HTTP requests. The client header remains reserved. |
fetch | Replaces the fetch function used by the transport. |
fetchMiddleware | Can inspect or change the request before fetch sends it. |
disableRetryOnRateLimit | Disables the built-in retry path for HTTP 429 responses. |
confirmTransactionInitialTimeout | Sets the initial wait used by transaction confirmation. |
subscriptions.channelConfig | Controls the WebSocket subscription channel runtime. |
In Node, callers can also provide the transport settings supported by the fetch environment. These settings are separate from the RPC method and affect the connection as a whole.
References: packages/…/connection.ts• L1763-1825 packages/…/connection.ts• L1827-1904 packages/…/connection.ts• L2663-2704
Request and response boundary
Public Connection methods turn client values into typed RPC calls and turn node responses into the data shapes used by the rest of the package. The boundary keeps wire concerns such as JSON-RPC envelopes, encodings, and numeric conversion out of most application code.
RPC requests
HTTP calls use JSON-RPC through a shared typed client. Request methods add the resolved commitment and method-specific options such as encoding, data slices, filters, transaction detail, or minimum context slot. Some methods group related reads or fetch several requested signatures in parallel. The HTTP RPC operations page covers these operation groups.
The transport retries HTTP 429 responses with increasing delays by default. It stops after a small retry budget, or immediately when rate-limit retry is disabled. Other transport errors and aborted requests pass to the caller.
References: packages/…/connection.ts• L1827-1872 packages/…/connection.ts• L2861-2899 packages/…/connection.ts• L3231-3314
RPC responses
The client accepts typed result values from the RPC layer and maps them into the public Connection model. Many state reads include a context with the slot at which the node evaluated the request. Account, block, transaction, and simulation results can also be converted from raw, parsed, or encoded forms selected by the request.
An RPC server error becomes a SolanaJSONRPCError with an operation-specific message. Send-transaction preflight failures can retain simulation logs for diagnosis. An HTTP status error remains a transport error, so callers can distinguish a failed request from a valid RPC response that reports an application or transaction error.
References: packages/…/connection.ts• L1920-1978 packages/…/connection.ts• L3231-3314 packages/…/connection.ts• L2947-2977
Compatibility adapters
The connection presents the established Connection API while its RPC client uses Solana Kit request and response types. Compatibility adapters build Kit request options and map Kit values back to the public client shapes. This lets existing callers use familiar account, transaction, block, and subscription types while the transport follows the newer Kit API.
The Kit adapters page explains this translation boundary. Changes to a public response shape must keep the matching request builder and response mapper aligned.
References: packages/…/connection.ts• L1-74 packages/…/connection.ts• L128-169 packages/…/connection.ts• L2168-2265
Connection lifecycle
HTTP access is prepared when the Connection is constructed. The WebSocket side is demand driven: it opens when the first subscription needs it, stays available while active subscriptions remain, and closes when no subscription needs the channel.
WebSocket session
The subscription runtime stores application subscription intent separately from the numeric IDs assigned by the node. This separation lets the client restore active subscriptions after a socket loss without requiring application code to register them again.
The session follows this cycle:
- A subscription is registered with the connection.
- The runtime opens a WebSocket channel when needed and sends the subscription request.
- The node returns a server subscription ID, which the runtime maps to the client subscription.
- Notifications are checked and routed to the registered callback.
- Removing the last client subscription sends the matching unsubscribe work and allows the channel to close.
- An unexpected disconnect marks active subscriptions for update when a new channel connects.
The WebSocket subscriptions page covers event types, callback behavior, and reconnect rules.
References: packages/…/connection.ts• L2720-2830 packages/…/connection.ts• L3666-3684 packages/…/runtime.ts• L1-220 packages/…/controller.ts• L1-260
Transaction confirmation
Transaction confirmation is a connection-level flow that combines RPC status reads with subscription or polling work. The caller can choose a legacy timeout strategy, a block-height expiry strategy, or a durable nonce strategy. The resolved commitment controls when the result is sufficient, and an abort signal can cancel pending confirmation.
This flow is separate from sending a transaction. A successful send only provides a signature; confirmation checks whether the cluster observes that signature at the requested level and reports expiry or transaction failure when applicable.
References: packages/…/connection.ts• L535-602 packages/…/connection.ts• L2327-2367 packages/…/connection.ts• L3600-3704
Change checklist
When these files or sections are changed, remember to consider these:
- Keep HTTP and WebSocket endpoint rules aligned when changing endpoint configuration or URL derivation.
- Preserve the commitment resolution order across ordinary requests, finality-only methods, subscriptions, and confirmation flows.
- Keep transport headers, custom fetch, middleware, abort signals, and 429 retry behavior compatible with each other.
- Keep Kit request builders and response mappers aligned with the public
Connectionresponse types. - Preserve the mapping between client subscription intent and server subscription IDs across reconnect and unsubscribe work.
- Keep JSON-RPC error context and transaction preflight logs available when changing error conversion.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
The endpoint does not start with http: or https:. | Connection construction fails before RPC work starts. | Pass an HTTP or HTTPS RPC endpoint. |
| The node returns HTTP 429 responses until the retry budget ends. | The request fails after backoff unless rate-limit retry is disabled. | Use suitable node limits or let the caller own retry policy. |
| A request uses a commitment below the method's supported finality. | The method rejects instead of sending an unsupported request. | Use confirmed or finalized where the method requires it. |
| The node returns a JSON-RPC error or incompatible result data. | The public call rejects instead of returning it as valid application data. | Handle the connection error and keep the adapter contract current. |
| The WebSocket closes while subscriptions are active. | Notifications pause until the runtime reconnects and restores the subscriptions. | Keep subscriptions registered while the application needs them. |
| A subscription callback throws. | That callback fails, but other callbacks for the notification can continue. | Handle callback errors in application code and keep callbacks independent. |
| A transaction expires or its preflight fails. | Confirmation or send rejects and may include expiry details or simulation logs. | Select a suitable confirmation strategy and inspect the structured error. |
Key files
| File | Why to read it |
|---|---|
| packages/…/connection.ts | Defines the public client boundary, shared request policy, response conversion, confirmation flows, and lifecycle wiring. |
| packages/…/runtime.ts | Shows how the WebSocket channel lives and reconnects. |
| packages/…/controller.ts | Shows how client subscriptions become server requests and notifications return to callbacks. |
| packages/…/request.ts | Shows how public request options become Solana Kit RPC options. |
| packages/…/response.ts | Shows how Kit responses become established Connection values. |
| packages/…/makeWebsocketUrl.ts | Shows how the default WebSocket endpoint relates to the HTTP endpoint. |
| docs/rpc-connection-operations.md | Explains the HTTP RPC operation groups behind this boundary. |
| docs/websocket-subscriptions.md | Explains subscription registration, notification handling, and reconnect behavior. |
| docs/kit-adapters.md | Explains the compatibility layer between the public client and Solana Kit APIs. |