Skip to main content

getFeeForMessage

Get the fee the network will charge for a particular Message

Common use cases
Fee Validation Before Transaction SubmissionCalculate exact transaction cost before sending to ensure fee payer has sufficient balance. Prevents transaction failures due to insufficient funds by validating balance >= message fee + account rent (if creating new accounts).
Send Maximum SOL AmountCompute the maximum transferable amount when emptying a wallet by subtracting the transaction fee from available balance. Essential for wallet draining operations where the user wants to send all remaining SOL.
Total Cost Calculation with Priority FeesCombine base transaction fee from getFeeForMessage with priority fees (from getRecentPrioritizationFees × compute units) to calculate complete transaction cost. Critical for competitive transaction landing during network congestion.

Parameters

message (string, required)

Base-64 encoded Message

config (object, optional)

Configuration object.

Fields:

  • commitment (string): The commitment describes how finalized a block is at that point in time. See Configuring State Commitment.
  • minContextSlot (number): The minimum slot that the request can be evaluated at.

Request

curl https://solana-mainnet.api.syndica.io/api-key/YOUR_API_KEY \
-X POST \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "getFeeForMessage",
"params": [
"AQABAgIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEBAQAA",
{
"commitment": "processed"
}
]
}'
Network Selection

Replace mainnet with devnet in the URL to query devnet instead.

Response

{
"jsonrpc": "2.0",
"result": {
"context": { "slot": 5068 },
"value": 5000
},
"id": 1
}

Response Fields

Return value: u64 | null

Fee corresponding to the message at the specified blockhash

FAQ and Troubleshooting

Why does getFeeForMessage return null?

Null indicates the blockhash in your message is invalid, expired, or not found in the blockhash queue. Ensure message has a recent blockhash (fetch with getLatestBlockhash) and call getFeeForMessage immediately after setting it.

What format does getFeeForMessage expect for the message parameter?

Base64-encoded string of the serialized message bytes. In web3.js v2/@solana/kit, serialize the transaction message then base64 encode it: getBase64Encoder().encode(messageBytes). Raw RPC calls require this encoding.

Does getFeeForMessage include priority fees in the returned value?

No. It returns only the base transaction fee (signatures × lamports_per_signature). Calculate priority fees separately using ComputeBudget instructions and add to base fee for total cost.

How does commitment level affect getFeeForMessage?

Commitment determines which blockhash queue is checked for fee calculation. Using 'processed' may return fees for very recent blockhashes, while 'finalized' only validates against finalized blockhashes. Most applications use 'confirmed' or omit for default behavior.

Can I use getFeeForMessage with versioned transactions?

Yes, as of @solana/web3.js v1.67.2. Earlier versions didn't support versioned transaction messages. Serialize the v0 message to bytes and base64 encode before passing to the RPC method.

getLatestBlockhash
Returns recent blockhash required for getFeeForMessage. Always fetch blockhash immediately before calling getFeeForMessage to avoid null responses from expired blockhashes.

getRecentPrioritizationFees
Provides current priority fee rates for transaction landing. Use together: base fee from getFeeForMessage + (priority fee rate × compute units) = total transaction cost.

simulateTransaction
Estimates compute units consumed by transaction. Essential for calculating priority fees when combined with getFeeForMessage for accurate total cost prediction.

getBalance
Returns account SOL balance. Compare with getFeeForMessage result to validate sufficient funds before transaction submission.

getMinimumBalanceForRentExemption
Calculates rent-exempt minimum for new accounts. Total required balance = getFeeForMessage + rent exemption for each new account + transfer amount.

External Resources