RPC Infrastructure
Public endpoints
(api.mainnet.solana.com) are rate-limited and carry no SLA. They suit
development and are not intended for production workloads. Use a
private RPC provider for production.
When choosing an RPC provider, compare:
- Reliability: an SLA with an uptime commitment
- Latency: geographic proximity to your users and servers
- Method coverage: the RPC methods your workload needs, and historical
depth that covers your reconciliation period
- Transaction landing: staked connections, priority fee APIs, and bundle
support where your workload depends on them
- Credential handling: separate keys per environment, and a way to rotate
them
For a full list of RPC providers, see the
RPC Infrastructure Providers guide.
Redundant RPC Configuration
Like any network service provider, RPC providers can experience downtime or
periods of degraded performance. To ensure your application is resilient, you
should configure your application to use multiple RPC providers.
Solana Kit
provides a library for customizing RPC transports which allows you to build your
own redundant RPC client. Here’s an example of how you might use it to build a
redundant RPC client:
import { RpcTransport } from "@solana/rpc-spec";
import { RpcResponse } from "@solana/rpc-spec-types";
import { createHttpTransport } from "@solana/rpc-transport-http";
// Create a transport for each RPC server
const transports = [
createHttpTransport({ url: "https://mainnet-beta.my-server-1.com" }),
createHttpTransport({ url: "https://mainnet-beta.my-server-2.com" }),
createHttpTransport({ url: "https://mainnet-beta.my-server-3.com" })
];
// Create a wrapper transport that distributes requests to them
let nextTransport = 0;
async function roundRobinTransport<TResponse>(
...args: Parameters<RpcTransport>
): Promise<RpcResponse<TResponse>> {
const transport = transports[nextTransport];
nextTransport = (nextTransport + 1) % transports.length;
return await transport(...args);
}
If you prefer not to build your own routing tools, you can use a third
party service like Iron Forge to handle the
routing for you.
Transaction Landing
On Devnet, transactions land fairly easily. On Mainnet, you’re competing for
block space. To increase the chances of having your transaction included in a
block, you should ensure you have properly assembled your transaction. This
means:
- including a fresh blockhash before sending the transaction
- including a priority fee instruction in the transaction with a competitive
priority fee
- including a compute unit limit instruction in the transaction with a compute
unit limit based on the estimated compute units required for the transaction
Additionally, you should consider other tools like Jito Bundles to increase the
chances of your transaction being included in a block. Let’s explore these tools
in more detail.
Transaction Send Configuration
When sending transactions on Mainnet, configure these parameters for optimal
landing rates:
Blockhash management:
- Fetch with
confirmed commitment
- Store the
lastValidBlockHeight returned by getLatestBlockhash—this tells
you when your transaction expires
- A blockhash is valid for 150 blocks, about 30 seconds at 200ms slots. For
converting slots to wall-clock time, see
settlement and finality
Send options:
maxRetries: 0 — Disable automatic RPC retries. Handle retries yourself so
you can refresh the blockhash when needed.
skipPreflight: true — Bypass simulation before sending. Use it only when the
transaction has already been simulated, for example to estimate its compute
units. Otherwise keep it false so simulation catches errors before a fee is
spent.
import { createSolanaRpc } from "@solana/kit";
const rpc = createSolanaRpc(process.env.RPC_URL!);
// 1. Get blockhash with confirmed commitment
const { value: latestBlockhash } = await rpc
.getLatestBlockhash({ commitment: "confirmed" })
.send();
// 2. Build and sign your transaction with the blockhash
// ... (transaction building code)
// 3. Send with production settings
const signature = await rpc
.sendTransaction(encodedTransaction, {
encoding: "base64",
maxRetries: 0n, // Handle retries yourself
skipPreflight: true, // Only after the transaction has been simulated
preflightCommitment: "confirmed"
})
.send();
// 4. Track expiration using lastValidBlockHeight
const { lastValidBlockHeight } = latestBlockhash;
// Stop retrying when current block height exceeds lastValidBlockHeight
Use Priority Fees
Every Solana transaction requires a transaction fee, paid in SOL. Transaction
fees are split into two parts: the base fee and the priority fee. Half of the
base fee is burned and half goes to the validator that processes the
transaction. The priority fee is an optional fee that increases the chance the
current leader will process your transaction.
How fees work:
Total fee = Base fee (5,000 lamports per signature) + Priority fee
Priority fee (legacy/v0) = ceil(compute_unit_price * compute_unit_limit / 1,000,000) lamports
Priority fee (v1 only) = Absolute total in lamports set in the message config
The base fee is a protocol constant; see
transaction fees. Priority fee levels move with
demand, so read the current distribution from
getRecentPrioritizationFees
or a provider’s fee API rather than from documentation.
Sample Implementation:
The
@solana-program/compute-budget
package provides a helper function to easily update or append the compute unit
price (in micro-lamports) instruction to a transaction.
import { updateOrAppendSetComputeUnitPriceInstruction } from "@solana-program/compute-budget";
const tx = pipe(
createTransactionMessage({ version: 0 }),
(m) => setTransactionMessageFeePayerSigner(payer, m),
(m) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, m),
(m) => appendTransactionMessageInstructions([myInstructions], m),
(m) => updateOrAppendSetComputeUnitPriceInstruction(1000n as MicroLamports, m)
);
Getting fee estimates: Most RPC providers offer priority fee APIs:
For the full fee mechanics, see Transaction Fees and our
guide:
How to Add Priority Fees to a Transaction.
Optimize Compute Units
Compute on Solana is effectively a measure of the amount of work the program is
doing. A transaction may use at most 1.4 million compute units, a fixed cap. The
per-block and per-writable-account limits are feature-gated
(SIMD-0286,
SIMD-0306)
and scale with the slot time under
SIMD-0525.
At the current 200ms target they are 50 million compute units per block and 20
million per writable account per block. Verify the current values against the
active feature gates; compute budget
explains the mechanism.
When you submit a transaction, you need to estimate the amount of compute that
will be used, and set the compute unit limit accordingly - this is effectively a
request for how much of the total capacity that should be reserved for your
transaction. In practice, this means properly estimating the compute units
required for your transaction is critical to having your transaction included in
a block (and important for managing your priority fees).
The Solana JSON RPC API has a
simulatetransaction method that can be
used to estimate the compute units required for a transaction, which includes an
estimate of the compute units that will be used.
@solana/kit provides helper functions that
estimate a transaction’s resource limits and set them on the message in one step
(using the simulatetransaction method under the hood). For version 1
transactions these helpers also estimate the loaded accounts data size limit.
import {
estimateResourceLimitsFactory,
estimateAndSetResourceLimitsFactory
} from "@solana/kit";
const estimateResourceLimits = estimateResourceLimitsFactory({ rpc });
const estimateAndSetResourceLimits = estimateAndSetResourceLimitsFactory(
estimateResourceLimits
);
const txWithResourceLimits = await estimateAndSetResourceLimits(tx);
If you build and send transactions with a kit plugin client, you typically
don’t need this step — the client adds compute budget instructions for you
when it sends (.sendTransaction()). The manual flow above is for when you
assemble transactions directly with @solana/kit.
In production, if you are repeating the same type of transaction multiple times,
you should consider caching the compute estimate for the transaction type to
avoid the overhead of estimating the compute units every time.
Jito Bundles
Jito bundles group several transactions so that they execute atomically and in
order when a Jito-connected leader includes them. Bundles are submitted to the
Jito network with a tip, which is an incentive for inclusion rather than a
guarantee of it.
Resources:
Retry Strategies
Transactions can fail for many reasons. Unlike traditional payment APIs that
return success/failure immediately, a Solana transaction requires confirmation
tracking.
Key concepts:
- Blockhash expiration: A transaction is valid for 150 blocks from its
blockhash, about 30 seconds at 200ms slots. The time varies with block
production, so use
lastValidBlockHeight to tell when the blockhash has
expired
- Idempotency: Resubmitting the same signed transaction is safe; it carries
the same signature and executes at most once. A transaction rebuilt with a new
blockhash is a new transaction, so rebuild only after the original’s blockhash
has expired
- Exponential backoff: Avoid overwhelming the network with rapid retries
import {
createSolanaRpc,
createSolanaRpcSubscriptions,
sendAndConfirmTransactionFactory,
isSolanaError,
SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED
} from "@solana/kit";
const rpc = createSolanaRpc(process.env.RPC_URL!);
const rpcSubscriptions = createSolanaRpcSubscriptions(process.env.RPC_WSS_URL!);
const sendAndConfirmTransaction = sendAndConfirmTransactionFactory({
rpc,
rpcSubscriptions
});
// Send with automatic confirmation tracking and block height monitoring
try {
await sendAndConfirmTransaction(signedTransaction, {
commitment: "confirmed",
// Optional: abort after 45 seconds
abortSignal: AbortSignal.timeout(45_000)
});
} catch (e) {
if (isSolanaError(e, SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED)) {
// Blockhash expired—rebuild transaction with fresh blockhash and retry
rebuildAndRetryTransaction(); // implement your own logic for rebuilding and retrying the transaction
}
throw e;
}
The sendAndConfirmTransactionFactory from @solana/kit handles confirmation
polling and block height tracking automatically. It throws
SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED when the transaction’s blockhash expires,
signaling that you need to rebuild the transaction with a fresh blockhash.
Additional Resources
Understanding Confirmation Levels
Solana exposes three commitment levels:
A block is finalized roughly 150 milliseconds after it is produced, and
confirmed reports the same block, so waiting for finalized costs nothing
extra. Use finalized for anything that feeds a book of record. Shorten any
timeout, retry, or interface delay that was sized for a multi-second wait.
Settlement and finality covers how finality
works, which level to use for the blockhash and for the result, and why
protocol finality is not legal finality.
For more on checking transaction status, see
Interacting with Solana.
Error Handling
Solana Kit provides typed errors via isSolanaError(). Use specific error codes
instead of string matching:
import {
isSolanaError,
SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED,
SOLANA_ERROR__TRANSACTION_ERROR__INSUFFICIENT_FUNDS_FOR_FEE,
SOLANA_ERROR__TRANSACTION_ERROR__BLOCKHASH_NOT_FOUND,
SOLANA_ERROR__TRANSACTION_ERROR__ACCOUNT_NOT_FOUND,
SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM,
type SolanaErrorCode
} from "@solana/kit";
function handlePaymentError(error: unknown): {
message: string;
retryable: boolean;
} {
// Errors arrive wrapped, sometimes several levels deep (for example
// "Transaction simulation failed" from client.sendTransaction), with the
// specific code further down the `cause` chain. Check every level.
const chain: unknown[] = [];
for (let c: unknown = error; c; c = isSolanaError(c) ? c.cause : undefined) {
chain.push(c);
}
const has = (code: SolanaErrorCode) =>
chain.some((c) => isSolanaError(c, code));
// Blockhash expired—rebuild and retry
if (
has(SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED) ||
has(SOLANA_ERROR__TRANSACTION_ERROR__BLOCKHASH_NOT_FOUND)
) {
return { message: "Transaction expired—rebuilding", retryable: true };
}
// Insufficient SOL for fees
if (has(SOLANA_ERROR__TRANSACTION_ERROR__INSUFFICIENT_FUNDS_FOR_FEE)) {
return { message: "Not enough SOL for fees", retryable: false };
}
// Fee payer account has never been funded ("no record of a prior credit")
if (has(SOLANA_ERROR__TRANSACTION_ERROR__ACCOUNT_NOT_FOUND)) {
return { message: "Fee payer account is not funded", retryable: false };
}
// Insufficient SOL or token balance: the System Program and the Token
// programs both return custom error 1. Other programs use code 1 for
// other errors, so check `context.index` if your transaction calls them.
if (
chain.some(
(c) =>
isSolanaError(c, SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM) &&
c.context.code === 1
)
) {
return { message: "Insufficient balance", retryable: false };
}
// Unknown error
console.error("Payment error:", error);
return { message: "Payment failed—please retry", retryable: true };
}
Preflight simulation errors reject with a top-level Transaction simulation failed error and carry the specific code further down the cause chain, which
is why the handler checks every level. BLOCK_HEIGHT_EXCEEDED is thrown at the
top level.
Common Error Codes:
Gasless Transactions
Users expect to pay in stablecoins, not acquire SOL for network fees. Gasless
transactions solve this—similar to how Venmo users don’t think about ACH fees.
See
Fee Abstraction
for complete implementation.