getFeeForMessage
The getFeeForMessage method returns the fee that would be charged to process a specific message at the current network conditions. This method allows you to estimate transaction fees before submitting transactions, which is essential for providing accurate fee estimates to users and preventing transaction failures due to insufficient balance.
Solana's fee structure is dynamic and based on transaction complexity rather than gas price bidding like Ethereum. Transaction fees are calculated based on the number of signatures required and the computational resources consumed. The base fee is measured in lamports per signature, with additional fees for computation units used by programs. This method takes a base64-encoded message (the transaction before signing) and returns the exact fee that would be charged if it were submitted in the current slot.
Accurate fee estimation is crucial for wallet applications, payment processors, and any dApp that needs to ensure users have sufficient balance to complete transactions. The fee returned includes all signature costs and can vary slightly based on network conditions and the priority fee market. This method helps developers build better user experiences by showing accurate costs before transaction submission.
Parameters
parameter | type | description |
|---|---|---|
message | string | Base64-encoded message for which to calculate the fee |
config | object | Optional configuration object |
config.commitment | string | Level of commitment: 'processed', 'confirmed', or 'finalized' (default: 'finalized') |
config.minContextSlot | number | Optional. Minimum slot that the request can be evaluated at |
Return Object
field | type | description |
|---|---|---|
context | object | RPC response context with slot information |
context.slot | number | The slot at which the fee was calculated |
value | number|null | Fee in lamports that would be charged for this message, or null if the blockhash in the message is expired or fee calculation failed |
Request Example
Response Example
Tip: The message must include a recent blockhash for the fee calculation to succeed. A null response indicates the blockhash is too old or invalid. Typical transaction fees on Solana are 5,000 lamports per signature (0.000005 SOL), making transactions very affordable. Priority fees can be added on top of this base fee.