Understanding Priority Fees on Solana
In blockchain networks, transaction speed and reliability are crucial for user experience and application performance. On the Solana blockchain, priority fees play a vital role in determining how quickly transactions are processed by validators. These optional fees allow users to "bid" for faster inclusion in blocks, especially during periods of high network congestion.
A priority fee is an additional cost—measured in micro-lamports per Compute Unit (CU)—that users can attach to their transactions beyond the base transaction fee of 5,000 lamports. Validators, who are responsible for confirming transactions, naturally prioritize those with higher fees per compute unit. This creates a dynamic market where users can balance urgency against cost.
While transactions without priority fees will still be processed, they may face delays when the network is busy. By strategically setting priority fees, developers and users can ensure timely execution without overpaying.
👉 Discover how real-time fee data can optimize your Solana transactions
Introducing getRecentPrioritizationFees
To help users make informed decisions about fee settings, Solana provides the getRecentPrioritizationFees RPC method. This powerful tool delivers up-to-date insights into recent priority fee activity across the network, enabling dynamic fee estimation based on actual usage patterns.
Instead of guessing or using static values, developers can now query real-world data to determine optimal fee levels. The method returns prioritization fee observations from recent blockchain slots, giving a clear picture of what other transactions are paying to get prioritized.
This functionality is particularly valuable for decentralized applications (DApps), wallets, and trading bots that require fast and reliable transaction processing on Solana.
How getRecentPrioritizationFees Works
The getRecentPrioritizationFees method retrieves an array of objects, each representing a prioritization fee observed in a recent slot. Each object contains:
- Slot: The blockchain slot number where the transaction was processed.
- prioritizationFee: The fee paid (in micro-lamports per CU) by at least one transaction in that slot.
Parameters
You can optionally pass an array of up to 128 base-58 encoded public key strings. This allows you to fetch fee data specifically related to certain accounts—ideal for monitoring DApps like Jupiter or Raydium.
If no addresses are provided, the method returns global network fee trends.
Use Cases
- Dynamic fee setting: Adjust fees in real time based on current network demand.
- Cost optimization: Avoid overpaying during low-traffic periods.
- Performance tuning: Ensure critical transactions (e.g., trades, bids) are confirmed quickly.
Setting Up Your Development Environment
To leverage this method effectively, you’ll need a direct connection to the Solana network. While public RPC endpoints work, using a dedicated node ensures reliability and higher rate limits.
Prerequisites
Before diving into code, ensure your environment includes:
- Node.js (v18 or later)
- npm (comes with Node.js)
- A Solana wallet with SOL for testing
We’ll use TypeScript for better code maintainability and type safety.
Initialize a TypeScript Project
Create a new project directory and set up the basics:
mkdir solana-priority-fees
cd solana-priority-fees
npm init -y
npm install typescript ts-node @types/node --save-dev
npx tsc --initThis creates a tsconfig.json file with default compiler options.
Install Required Dependencies
Install the necessary libraries:
npm install @solana/web3.js dotenv@solana/web3.js: Official Solana JavaScript SDK.dotenv: For securely managing environment variables.
Update your package.json with a script shortcut:
"scripts": {
"start": "ts-node main.ts"
}Configuring Environment Variables
Security is key when handling blockchain interactions. Never hardcode sensitive data like RPC URLs or private keys.
Create a .env file in your project root:
SOLANA_RPC=https://your-chainstack-solana-node.solana-mainnet.discover.quiknode.pro/abc123/Load these variables in your code using dotenv:
import * as dotenv from 'dotenv';
dotenv.config();Access them via process.env.SOLANA_RPC.
👉 Learn how secure API access improves transaction reliability
Implementing getRecentPrioritizationFees in Code
Now let’s build a script that fetches and analyzes recent prioritization fees.
Define Types and Configuration
Start by defining interfaces for type safety:
interface PrioritizationFeeObject {
slot: number;
prioritizationFee: number;
}
interface Config {
accountKeys?: string[];
}Fetch and Analyze Fee Data
Here’s a complete example in main.ts:
import { Connection, PublicKey } from '@solana/web3.js';
import * as dotenv from 'dotenv';
dotenv.config();
function getEnvVariable(key: string): string {
const value = process.env[key];
if (!value) throw new Error(`Environment variable ${key} is not set`);
return value;
}
async function getPrioritizationFees() {
const rpcUrl = getEnvVariable('SOLANA_RPC');
const connection = new Connection(rpcUrl);
const config: Config = {
accountKeys: ['JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4'] // Jupiter address
};
try {
const fees: PrioritizationFeeObject[] = await connection.getRecentPrioritizationFees(config);
if (fees.length === 0) {
console.log("No recent prioritization fee data available.");
return;
}
const feeValues = fees.map(f => f.prioritizationFee);
const nonZeroFees = feeValues.filter(f => f > 0);
const minSlot = Math.min(...fees.map(f => f.slot));
const maxSlot = Math.max(...fees.map(f => f.slot));
const averageIncludingZeros = feeValues.reduce((a, b) => a + b, 0) / feeValues.length;
const averageExcludingZeros = nonZeroFees.reduce((a, b) => a + b, 0) / nonZeroFees.length;
const sortedFees = nonZeroFees.sort((a, b) => a - b);
const medianFee = sortedFees[Math.floor(sortedFees.length / 2)];
console.log(`Analyzed ${fees.length} slots from #${minSlot} to #${maxSlot}`);
console.log(`Avg Fee (with zeros): ${averageIncludingZeros.toFixed(2)} micro-lamports/CU`);
console.log(`Avg Fee (no zeros): ${averageExcludingZeros.toFixed(2)} micro-lamports/CU`);
console.log(`Median Fee: ${medianFee} micro-lamports/CU`);
} catch (error) {
console.error("Error fetching prioritization fees:", error);
}
}
getPrioritizationFees();Run it with:
npm startInterpreting the Results
The output gives you actionable metrics:
- Use median fee to avoid outlier influence.
- Compare average with/without zeros to detect network congestion.
- Monitor trends over time to predict fee spikes.
These values can be fed directly into your transaction logic to set competitive yet cost-effective priority fees.
Frequently Asked Questions
Q: What are micro-lamports?
A: A micro-lamport is one-millionth of a lamport—the smallest unit of SOL. Fees are quoted in micro-lamports per Compute Unit for precision.
Q: Can I use getRecentPrioritizationFees without specifying account keys?
A: Yes. Omitting the accountKeys parameter returns system-wide fee data, useful for general network analysis.
Q: How often should I poll this method?
A: Every 10–30 seconds is sufficient for most use cases. Frequent polling isn’t necessary unless you're building high-frequency trading systems.
Q: Does this method work on all Solana clusters?
A: Yes, it's supported on mainnet-beta, devnet, and testnet.
Q: Are priority fees guaranteed to speed up my transaction?
A: Not guaranteed, but significantly increase chances. Validators prioritize higher-paying transactions, so competitive fees improve inclusion odds.
Q: Can I set different priority fees for different parts of my transaction?
A: No. The entire transaction uses a single compute budget and fee rate. Optimize instruction order and resource usage instead.
👉 See how advanced fee strategies enhance blockchain performance
Core Keywords
- Solana priority fees
- getRecentPrioritizationFees
- micro-lamports per compute unit
- Solana transaction speed
- dynamic fee estimation
- Solana web3.js
- blockchain transaction optimization
Conclusion
The getRecentPrioritizationFees method empowers developers to make data-driven decisions when setting transaction fees on Solana. By analyzing real-time network behavior, you can dynamically adjust fees to balance speed and cost—ensuring efficient, responsive DApp performance even during peak loads.
Whether you're building a wallet, DeFi platform, or NFT marketplace, integrating this method enhances user experience by reducing failed or delayed transactions. With proper implementation using TypeScript and secure environment management, you can future-proof your applications against fluctuating network conditions.
As Solana continues to scale, tools like this become essential for maintaining performance and competitiveness in the fast-moving world of Web3.