The Solana RPC spec supports a method called getRecentPriorityFees
. This method pulls data from a cache on an RPC node that stores up to the last 150 blocks. The response is defined by GetRecentPriorityFeesResponse
:
type GetRecentPriorityFeesResponse = Vec<RpcPrioritizationFee>
struct RpcPrioritizationFee {
slot: u64
prioritization_fee: u64
}
Here, prioritization_fee is calculated on a per-slot basis:
prioritization_fee(slot) = MAX(min_txn_fee, MAX(min_writeable_account_fee(tx))
A good way to approximate priority fees for a given transaction is to take the median of the data received from getRecentPriorityFees
for given writable accounts. This ensures that the priority fees is above the minimum required but not wasteful either.
Helius also has an API for this.