Learn getFeeForMessage use cases, code examples, request parameters, response structure, and tips.
getFeeForMessage
RPC method allows you to estimate the fee the network will charge for processing a given transaction message. This is useful for understanding transaction costs before they are submitted to the network.
Version Note: This method is available in solana-core
v1.9 or newer. For older versions, consider using getFees
.
message
(string, required): The transaction message, base64 encoded. You can obtain this by compiling a transaction.config
(object, optional): A configuration object with the following fields:
commitment
(string, optional): Specifies the commitment level to use. Defaults to finalized
.minContextSlot
(number, optional): The minimum slot at which the request can be evaluated.result
field of the JSON-RPC response is an object with the following structure:
context
(object):
slot
(u64): The slot at which the fee was evaluated.value
(u64 | null): The estimated fee in lamports. This can be null
if the fee cannot be determined (e.g., if the blockhash used in the message is too old or invalid).getFeeForMessage
is to correctly construct and serialize the transaction Message
. This involves setting the fee payer, instructions, and a recent blockhash.value
in the response might be null
.getRecentPrioritizationFees
to estimate priority fees.null
value for the fee can indicate issues with the message (e.g., invalid blockhash, malformed message) or that the node cannot calculate a fee for it at the given commitment level or slot.getFeeForMessage
RPC method for estimating transaction fees on the Solana network.