RPC connection operations
Connection is the request-and-response interface to a Solana JSON-RPC node. It lets an application read account, ledger, and transaction state, estimate fees, test transactions, submit signed transactions, and check their results. The wider client boundary is described in Connection and RPC client; live updates use WebSocket subscriptions, and typed response compatibility is related to Kit adapters.
Connection boundary
The Connection class sends application requests to one configured RPC endpoint. It applies a connection-wide commitment by default, then accepts a commitment or config object for a single operation. The request layer converts web3.js values to RPC values and maps RPC results back to the public Connection shapes.
HTTP request path
The HTTP path sends JSON-RPC requests to the endpoint passed to Connection. Construction can set headers, a custom fetch function, fetch middleware, and rate-limit retry behavior. The connection also creates a WebSocket client, but its subscription behavior belongs to WebSocket subscriptions.
The request path follows this broad flow:
flowchart LR
A[Application call] --> B[Connection operation]
B --> C[Commitment and request config]
C --> D[HTTP JSON-RPC request]
D --> E[Solana RPC node]
E --> F[Mapped result or RPC error]
F --> A
References: packages/…/connection.ts• L1949-2040 packages/…/connection.ts• L2915-3048
Account state
Account operations provide the on-chain state that programs and wallets use to make decisions. They support single and grouped reads, program-owned account scans, and token account queries.
Account queries
getAccountInfo returns raw account data, while getParsedAccountInfo asks the node for a known parsed form. Context variants also return the node slot that produced the value. An account that is not present returns null.
Account reads can also:
- Read several accounts in one request.
- Filter program accounts by data size or byte patterns.
- Select token accounts by owner or delegate.
- Return only a data slice when the full account data is not needed.
- Require the node to evaluate the request at or above a minimum context slot.
References: packages/…/connection.ts• L769-778 packages/…/connection.ts• L3452-3569 packages/…/connection.ts• L3753-3795
Account-derived state
Some reads turn account data into higher-level state. Address lookup table reads check that the account belongs to the lookup table program before decoding it. Nonce reads decode a nonce account and keep the RPC context. These results support transaction creation and durable-nonce confirmation.
References: packages/…/connection.ts• L5961-6015
Ledger state
Ledger operations expose the cluster view needed to locate blocks, inspect their contents, and track slots and block progress. Some results include RPC context so callers can relate data to the slot at which the node observed it.
Block queries
getBlock and getParsedBlock fetch a block by slot. Their options select finality, rewards, transaction detail, and the highest transaction version the caller can read. Transaction detail can include full transactions, account-focused data, signatures, or no transactions. Range queries return block slots, while block commitment and signature queries provide smaller block views.
Other ledger reads provide the latest blockhash and expiry height, block time and height, block production, leader schedules, epoch data, and recent performance. Applications use these values to show network state and to manage transaction lifetime.
References: packages/…/connection.ts• L793-830 packages/…/connection.ts• L5041-5215 packages/…/connection.ts• L5217-5317 packages/…/connection.ts• L5494-5615
Transaction history
Transaction history can be read by signature or by address. getTransaction and getParsedTransaction return one transaction with its message and execution metadata. Batch forms preserve a null result when a requested transaction is unavailable. Address history supports backward signature paging through before, until, and limit.
getTransactionsForAddress adds provider-dependent history search with server-side filters, sort order, and cursor pagination. It can return signature-level results or full transactions in JSON, parsed JSON, base58, or base64 form. It is not a native validator method, so an RPC provider must support it.
Block and transaction history use at least confirmed finality. A processed request is rejected before it reaches the node for methods that only support confirmed or finalized data.
References: packages/…/connection.ts• L943-962 packages/…/connection.ts• L5320-5457 packages/…/connection.ts• L5693-5959
Fee and simulation services
Fee and simulation operations answer questions that normally come before submission. They use a message or transaction as input and return the node's estimate, execution result, or both.
Fee queries
getFeeForMessage estimates the fee for a serialized message at a selected commitment and minimum context slot. A null fee is treated as an invalid blockhash. getRecentPrioritizationFees reports recent fees for transactions that lock selected writable accounts, which helps an application choose an additional fee.
Rent exemption, supply, token supply, token balance, and largest-account queries provide related balance and network data. The latest blockhash query returns the blockhash with its last valid block height, which gives transaction builders a usable lifetime boundary.
References: packages/…/connection.ts• L885-902 packages/…/connection.ts• L4781-4907 packages/…/connection.ts• L4909-4961
Transaction simulation
simulateTransaction evaluates a transaction without submitting it for ledger processing. It accepts a versioned transaction directly and keeps compatibility with legacy transaction and message inputs. The result can report execution errors, logs, account state, inner instructions, return data, fees, and resource use.
Simulation options select signature checks, recent blockhash replacement, commitment, minimum context slot, returned accounts, and inner instructions. Signature verification and blockhash replacement cannot be used together because they test different transaction conditions. Legacy inputs may be signed by supplied signers, and the connection obtains a recent blockhash when needed.
References: packages/…/connection.ts• L1126-1160 packages/…/connection.ts• L6167-6384
Transaction submission
Submission moves a signed transaction from the client to the RPC node. Connection supports signing a legacy transaction before sending, sending an already signed versioned transaction, and sending serialized transaction bytes.
Send operations
sendTransaction prepares the transaction and delegates to the serialized send path. For a legacy transaction, the connection supplies a recent blockhash and its expiry height before signing. sendRawTransaction accepts serialized bytes, while sendEncodedTransaction accepts an already base64-encoded wire transaction.
Send options control preflight, the commitment used for preflight, a minimum context slot, and the node's retry limit. Unless preflight is skipped, the node simulates the transaction before accepting it. A preflight failure is surfaced with its message and available logs through SendTransactionError.
This sequence shows how simulation, submission, and later confirmation relate:
sequenceDiagram
participant App as Application
participant C as Connection
participant RPC as RPC node
App->>C: sendTransaction or sendRawTransaction
C->>RPC: sendTransaction with preflight options
RPC-->>C: signature or preflight error
C-->>App: signature or SendTransactionError
App->>C: confirmTransaction
C->>RPC: status and confirmation checks
RPC-->>C: signature result
C-->>App: confirmation result
References: packages/…/connection.ts• L499-512 packages/…/connection.ts• L6386-6529
Confirmation operations
confirmTransaction checks whether a submitted signature reaches the requested commitment. It accepts a signature for the legacy timeout path, a block-height strategy for blockhash expiry, or a durable-nonce strategy for nonce expiry. An abort signal can stop an active confirmation.
Confirmation is separate from submission. A returned signature means that the node accepted the request for processing. It does not mean that the transaction reached the commitment required by the application.
References: packages/…/connection.ts• L631-703 packages/…/connection.ts• L3798-3853 packages/…/connection.ts• L4022-4299
Commitment and configuration
Commitment and request configuration define which cluster state a method may use and how much data or work it should return. The connection applies its default first, then lets a method-specific string or config object override it.
Commitment levels
The connection resolves an omitted commitment to the per-connection setting, or to confirmed when no setting exists. processed gives the newest view reached by the connected node. confirmed gives a cluster-confirmed view. finalized gives a finalized cluster view.
Block and transaction history methods accept only confirmed or finalized. The connection rejects a weaker level because those RPC methods cannot provide it. Per-call config objects use the same commitment field as the shorthand string form.
References: packages/…/connection.ts• L714-727 packages/…/connection.ts• L741-757 packages/…/connection.ts• L3870-3882
Request options
Request options shape the returned data or constrain where the node evaluates a request. The main groups are:
| Option group | Purpose |
|---|---|
minContextSlot | Prevents evaluation below a known slot. |
dataSlice and account encoding | Controls account data size and form. |
filters | Limits program or token account results. |
transactionDetails and maxSupportedTransactionVersion | Controls block or history detail and supported transaction versions. |
rewards and includeAccounts | Controls optional block or simulation data. |
before, until, limit, and pagination fields | Pages or filters address transaction history. |
skipPreflight, preflightCommitment, and maxRetries | Controls transaction submission. |
At construction time, ConnectionConfig sets the endpoint-wide commitment and transport behavior. It can also set HTTP headers, fetch hooks, rate-limit retry behavior, the WebSocket endpoint, subscription channel settings, and the initial confirmation wait period. HTTP 429 responses are retried with backoff unless disableRetryOnRateLimit is enabled.
References: packages/…/connection.ts• L2857-2899 packages/…/connection.ts• L1949-1993 packages/…/connection.ts• L6482-6529
Change checklist
When these files or sections are changed, remember to consider these:
- Keep raw, parsed, encoded, versioned, and reduced transaction detail modes aligned when block or history response shapes change.
- Keep the
confirmeddefault and the confirmed-or-finalized restriction aligned across read methods and confirmation behavior. - Keep
preflightCommitment,skipPreflight, andSendTransactionErroraction and log mapping aligned with the node's send response. - Keep recent blockhash, expiry height, block-height confirmation, and durable nonce paths consistent when transaction lifetime rules change.
- Keep provider-specific address history behavior distinct from native validator RPC methods.
- Keep custom fetch, middleware, headers, and HTTP 429 retry behavior aligned with the RPC transport contract.
- Keep typed RPC response mappings aligned with the public
Connectionresult shapes when RPC schemas change. - Keep request operations separate from the subscription contracts in WebSocket subscriptions.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
A block or transaction query uses processed commitment. | The connection rejects the call because those methods require confirmed or finalized state. | Use confirmed or finalized. |
| A message has an invalid or expired blockhash during fee lookup. | getFeeForMessage fails instead of returning an estimate. | Fetch a current blockhash and check its lifetime before building or sending. |
| A response contains a transaction version the caller does not support. | The node cannot return the requested transaction or block shape. | Set maxSupportedTransactionVersion to a version the caller can read. |
A provider does not implement getTransactionsForAddress. | Address history lookup fails because the method is not part of the native validator RPC set. | Check provider support before using the method. |
| Submission preflight fails. | The transaction is not accepted and the caller receives a SendTransactionError with the failure message and possible logs. | Simulate first or inspect the logs before retrying. |
| The RPC node returns HTTP 429 repeatedly. | The request waits through built-in backoff or fails after retries. | Use a suitable endpoint and disable built-in retry only when the caller owns the retry policy. |
| An account or transaction is not present at the selected state. | The read returns null or a missing result. | Choose the needed commitment and handle absent data as a normal result. |
Key files
| File | Why to read it |
|---|---|
| packages/…/connection.ts | Defines the Connection boundary, request groups, commitment rules, transport behavior, simulation, submission, and confirmation. |
| docs/connection-and-rpc.md | Places request operations in the wider connection and RPC client model. |
| docs/websocket-subscriptions.md | Explains the live event path that complements these one-request operations. |
| docs/kit-adapters.md | Explains the compatibility boundary between typed RPC data and the web3.js API. |